I want to use jquery to limit the number of characters in an editable div (or form input).
相关问题
- Views base64 encoded blob in HTML with PHP
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
make use of
maxlength
ininput
tagMaxlength attribute- for browser, that support this feature.
Javascript - for others.
http://jsfiddle.net/tvpRT/
This should work for you I think.
HTML
jQuery
Let's say it is form input.
you can do it with 'maxlength' attribute but if you say 'using jQuery',
here's the solution.
or you can check every keypress
As for input field you can use maxlength attribute. If you are looking for div, check the following,
Edit: you should rewrite the checkMaxLength function to ignore tabs and newline
just use attribute called "maxlength". You can read more about input's attributes at w3 input