限制文本框输入长度

function Count(text,long)

 

{

 

      var maxlength = new Number(long); // Change number to your max length.

 

if(document.getElementById('<%=textBox.ClientID%>').value.length > maxlength){

 

            text.value = text.value.substring(0,maxlength);

 

            alert(" Only " + long + " chars");

 

}

 


Where “textBox” is the asp text box ID.
Also add following events in your textbox.

onKeyUp="javascript:Count(this,200);" onChange="javascript:Count(this,200);"


Your textbox code should look like

 

<asp:TextBox ID="textBox" onKeyUp="javascript:Count(this,2);" onChange="javascript:Count(this,2);" TextMode=MultiLine Columns="5" Rows="5" runat=server>

    </asp:TextBox>

posted on 2009-03-19 11:57  QZB.NET  阅读(1138)  评论(1)    收藏  举报