TextArea限制输入长度

cs文件中添加文本框属性this.TextBox.Attributes.Add("MaxLength", "200");

 1  $(document).ready(function() {
 2             $("textarea").each(function() {
 3                 var maxLength = $(this).attr("MaxLength");
 4                 if (maxLength) {
 5                     $(this).bind("keyup", "", function(e) {
 6                         var le = $(this).val().len();
 7                         if (le > maxLength) {
 8                                 $(this).val($(this).val().substring(0,maxLength))
 9                         }
10                     });
11                 }
12             });
13         });
14         //返回字符串的实际长度, 一个汉字算2个长度
15         String.prototype.len = function() {
16             return this.replace(/[^x00-xff]/g, "**").length;
17         }
原文地址:https://www.cnblogs.com/xiaoyu369/p/3241059.html