<scriptlanguage="javascript">
<!--
functiontextCounter(field,maxlimit)
{
varstr="";
str=field.value;
str=str.replace(/[^\x00-\xff]/g,"**");
if(str.length>maxlimit)
{
//field.value=field.value.substring(0,maxlimit);
field.value=getByteOfNum(field.value,maxlimit);
}
}
functiongetByteOfNum(val,num)
{
varch,bytenum=0;
varrs="";
varpt=/[^\x00-\xff]/;
for(vari=0;i<num;i++)
{
ch=val.substr(i,1);
if(ch.match(pt))
{
bytenum+=2;
if(bytenum>num)
{
returnrs;
}
}else
{
bytenum+=1;
}
rs+=ch;
if(bytenum==num)
{
returnrs;
}
}
returnrs;
}
//-->
aspx中调用的代码:
<asp:textboxid="txtAttendOuter"runat="server"onkeydown="textCounter(this.form.txtAttendOuter,100);"
onkeyup="textCounter(this.form.txtAttendOuter,100);"Width="145px"></asp:textbox>