Js controls the number of input strings in textarea. Press the mouse and hold it up to determine the number of input characters. jstextarea
[Html code]
<Table>
<Tr>
<Td width = "150"> text message content: </td>
<Td>
<Textarea name = "message" cols = "96" rows = "5" onKeyDown = "textCounter (message, remLen, 65 );"
OnKeyUp = "textCounter (message, remLen, 65);"> </textarea>
<Td>
</Tr>
<Tr> <td> </td>
<Td> You can also enter <input name = "remLen" type = "text" value = "65" size = "5" readonly = "readonly"> characters, each text message can contain up to <strong> 65 </strong> characters </td>
</Tr>
</Table>
[Corresponding js Code]
<Script>
Function textCounter (field, countfield, maxlimit ){
If (field. value. length> maxlimit)
Field. value = field. value. substring (0, maxlimit );
Else
Countfield. value = maxlimit-field. value. length;
}
</Script>
Js question: How does one specify the number of characters in a string?
Check whether this meets your requirements.
Public class Test {
Public static void main (String [] args ){
Test t = new Test ();
String s = "wohoeniohoaoohah ";
String c = "o ";
Int x = t. getNum (s, c );
System. out. println (x );
}
Public int getNum (String s, String c) {// s is the original String. c is the String we are looking for. Of course, it can be a character.
Int x = s. indexOf (c); // checks whether C exists in S! If x =-1, it indicates no.
Int sum = 0; // number of occurrences!
While (x! =-1 ){
Sum ++;
S = s. replaceFirst (c, ""); // replace C with "". recyclically find the next C
X = s. indexOf (c );
}
Return sum;
}
}
How can I use JavaScript to limit the number of characters in multiple lines of text fields? to limit the number of characters in a single line of text box, it cannot appear again after entering the specified number of characters
In this way:
<Textarea oninput = "s ()" onpropertychange = "s ()"> </textarea>
Function s (){
Var leng = number of characters to limit
If (this. value. lengtg> = leng ){
// Add a limit to achieve stronger results
Event. returnValue = false; // when the number of words reaches the specified value, any buttons are invalid.
// Truncate the string
This. value = this. value. substring (0, leng );
}
}
Because onpropertychange is only valid in IE, and oninput is valid in most browsers, the two are used together.