<HTML> <Head> <title>Controlling input character length in textarea</title> </Head><Body> <textareaname= "Content"cols= "$"rows= "6"onkeydown= "if (this.value.length > Event.returnvalue) = false"></textarea></Body></HTML>
The above code through the onkeydown event, when the input character length exceeds 140, set Event.returnvalue to False, this property can be canceled in the event handler to call the function of the default action.
<HTML><Head> <title>Controlling input character length in textarea</title></Head><Body> <form> <textareaname= "Content"cols= "$"rows= "6"onkeyup= "if (this.value.length > This.value) = this.value.substr (0,140)"></textarea> </form></Body></HTML>
Here through the onkeyup can also control the input string length of not more than 140, but the processing does not have the above way good, here will first show the user input of all content, and then to intercept, the content will be more than the first to delete, the effect is not very good
How to control the length of characters entered in textarea