多行文本框长度限制

function   maxCheck(ele,maxLength)  
              {  
                  var   maxLengh_Bak   =   maxLength;  
                  var   length   =   ele.value.length;  
                  var   i;  
                  for(i=0;i<length;i++)  
                  {  
                    if (/^[\u4E00-\u9FA5]+$/g.test(ele.value.charAt(i)))  
                       {  
                          maxLength=maxLength-2;  
                       }  
                    else  
                       {  
                         maxLength--;  
                       }  
                    if (maxLength<0)  
                      {        
                        alert("长度不能超过"   +   maxLengh_Bak   +   "个字符");  
                        ele.value=ele.value.slice(0,i);  
                        return;      
                  }  
              }       
               return;  
             }

调用: TextBox1.Attributes["onchange"] = "maxCheck(this,10)";

你可能感兴趣的:(文本框)