This article mainly introduces jQuery's method to limit the number of characters entered in the textarea text box, involving operations related to jQuery Keyboard Events and page elements, for more information about how jQuery limits the number of characters entered in the textarea text box, see the following example. Share it with you for your reference. The specific implementation method is as follows:
(Function ($) {$. fn. extend ({limiter: function (limit, elem) {$ (this ). on ("keyup focus", function () {setCount (this, elem) ;}); function setCount (src, elem) {var chars = src. value. length; if (chars> limit) {src. value = src. value. substr (0, limit); chars = limit;} elem.html (limit-chars);} setCount ($ (this) [0], elem );}});}) (jQuery); // To setup the limiter, simply include a call similar to the one below: var elem =$ ("# chars"); $ ("# text "). limiter (100, elem );
I hope this article will help you with jQuery programming.