But textarea does not have this attribute.
asp.net service-side TextBox This property does not work, so we only use the JS script to control the
good, nonsense not much to say, first on the code
Javascipt Source:
Copy Code code as follows:
function textcounter (field, Maxlimit, lines) {//Parameter description: field is a TextArea object, Maxlimit is the maximum allowable length, lines is the number of rows
var arr = field.value.split ("\ n");//First we have to validate the number of rows, "\ n"
var perline = "";
var value = ""; The
if (Arr.length < lines) lines = arr.length;//Determines whether the number of rows exceeds the number of rows we specify, and if the number of rows is exceeded, change the row count to exceed, because we want to count the string length
for (loop = 0; Loop & Lt Lines loop++) {///cyclic measurement string total length, not much said
Perline = Arr[loop];
if (Perline.length > Maxlimit)
perline = perline.substring (0, Maxlimit);
Value = value + perline;
if (loop!= lines-1)
Value = value + "\ n";
}
if (field.value!= value)
Field.value = value;
if (checkstr (value, Maxlimit)) {//To determine if the string length is exceeded
Field.value = value.substring (0, maxlimit);//delete extra string
}
}
function showoverwords (obj, maxlength) {//Display the remaining number of available input characters obj is the Txteara object, maxlength maximum length
len = Obj.value. Length
$ ("#wordCount"). HTML (Maxlength-len);//This is jquery, and you can compare yourself.Change. Represents the modification of the value of the ID wordcount label
}
Function checkstr (str, digit) {//Judging Chinese and English, whether the length of the string is exceeded
var n = 0;
for (i = 0; i < str.length i++) {
var leg = str.charcodeat (i);//ascii code
if (Leg > 255) {//greater than 255 are all Chinese
N + = 2;//If it is Chinese is 2 bytes
Else {
N + + 1;//English, don't say more
}
}
if (n > Digit) {
Return T Rue
} else {
return false;
}
}
OK there are three functions, we can call these three functions to achieve the function we want