Posted in Javascript onJanuary 16, 2017
本文实例讲述了jQuery实现简易的输入框字数计数功能。分享给大家供大家参考,具体如下:
运行效果图如下:
具体代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.7.2.min.js"></script> </head> <body> <div class="container"> <input id="abc" value="三水点靠木"><span id="wordCountShow"></span> </div> <script> $.fn.extend({ wordCount: function (maxLength, wordWrapper) { var self = this; $(self).attr("maxlength", maxLength); showWordCount(); $(this).on("input propertychange", showWordCount); function showWordCount() { curLength = $(self).val().length; var leaveCount = maxLength - curLength; wordWrapper.text(leaveCount + "/" + maxLength); } } }) $(function () { $("#abc").wordCount(10, $("#wordCountShow")); }) </script> </body> </html>
jQuery实现简易的输入框字数计数功能示例
- Author -
ISaiSai声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@