【www.bbyears.com--jquery】
运行效果图如下:
具体代码如下:
<script src="jquery-1.7.2.min.js"></script> <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>