<scriptlanguage=
javascript
>
<!
functiontextCounter(fieldmaxlimit)
{
varstr=;
str=fieldvalue;
str=strreplace(/[^\x\xff]/g**);
if(strlength>maxlimit)
{
//fieldvalue=fieldvaluesubstring(maxlimit);
fieldvalue=getByteOfNum(fieldvaluemaxlimit);
}
}
functiongetByteOfNum(valnum)
{
varchbytenum=;
varrs=;
varpt=/[^\x\xff]/;
for(vari=;i<num;i++)
{
ch=valsubstr(i);
if(chmatch(pt))
{
bytenum+=;
if(bytenum>num)
{
returnrs;
}
}else
{
bytenum+=;
}
rs+=ch;
if(bytenum==num)
{
returnrs;
}
}
returnrs;
}
//>
aspx中调用的代码
<asp:textboxid=txtAttendOuterrunat=serveronkeydown=textCounter(thisformtxtAttendOuter);
onkeyup=textCounter(thisformtxtAttendOuter);Width=px></asp:textbox>