textarea内容限制字数

1. <textarea id="area" name="ss" placeholder="请输入文本内容"></textarea> 
2. <p><span id="text-count">20</span>/20</p> 
3. <script type="text/javascript"> 
4.     /*字数限制*/ 
5.     $("#area").on("input propertychange", function() { 
6.         var $this = $(this), 
7.             _val = $this.val(), 
8.             count = ""; 
9.         if (_val.length > 20) { 
10.             $this.val(_val.substring(0, 20)); 
11.         } 
12.         count = 20 - $this.val().length; 
13.         $("#text-count").text(count); 
14.     }); 
15. </script> 

原文地址:https://www.cnblogs.com/gerry/p/6946254.html