Home > Article > Web Front-end > jQuery operates input box to count word count
This time I will bring you jQueryOperation input box to count the number of words, jQuery operation input box to count the number of wordsWhat are the precautions, the following is a practical case, let's come together take a look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.7.2.min.js"></script> </head> <body> <p class="container"> <input id="abc"value=""><span id="WordCountShow"></span> </p> <script> $.fn.extend({ wordCount:function(maxLength, wordWrapper) { varself =this; $(self).attr("maxlength", maxLength); showWordCount(); $(this).on("input propertychange", showWordCount); functionshowWordCount() { curLength = $(self).val().length; varleaveCount = maxLength - curLength; wordWrapper.text(leaveCount +"/"+ maxLength); } } }) $(function() { $("#abc").wordCount(10, $("#wordCountShow")); }) </script> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
jQuery cookie to achieve skin-changing effect
jQuery to create page mask layer effect
The above is the detailed content of jQuery operates input box to count word count. For more information, please follow other related articles on the PHP Chinese website!