js 实现textarea剩余字数统计
1 针对textarea剩余字数统计 2 <div class="fankui-textarea"> 3 <span>留言:</span> <span class="wordwrap fr">你还可以输入<var class="word">500</var>个字</span> 4 <textarea name="content" placeholder="此处限定500字"></textarea> 5 </div> 6 <script> 7 /*textarea还剩余字数统计*/ 8 $(function () { 9 var wordCount = $('.fankui-textarea'); 10 var textArea = wordCount.find('textarea'); 11 var word = wordCount.find(".word"); 12 statInputNum(textArea, word); 13 }); 14 function statInputNum(textArea, word) { 15 var max = word.text(); 16 var curLength; 17 textArea[0].setAttribute('maxlength', max); 18 curLength = textArea.val().length; 19 word.text(max-curLength); 20 textArea.on('input propertychange', function () { 21 var _value = $(this).val().replace(/\n/gi,""); 22 word.text(max - _value.length); 23 }); 24 } 25 </script>