Citation: http://aqingsao.iteye.com/blog/398897
TextArea is often used in web development, but it does not natively support maxlength, which can be implemented with the following JS:
JS Code
- function limit_textarea_input () {
- $ (" textarea[maxlength] "). Bind ( ' input PropertyChange ', function () {
- var maxLength = $ (this). attr ( ' maxlength ');
- if ($ (this). Val (). length > MaxLength) {
- $ (this). Val ($ (this). Val (). substring (0, maxLength));
- }
- })
- }
By listening to the input event (Firefox, Safari ...) and PropertyChange events (IE), limit the length of the textarea input box.
This allows you to add the MaxLength attribute to the input box that needs to limit the length:
Java code
- <textarea rows= '5 ' cols= ' maxlength= ' name= '></textarea>
where rows and cols can not be written, but MaxLength is required
Then the page loads bound events:
Java code
- $ (limit_textarea_input)
HTML textarea Input box limit length (citation)