Copy codeThe Code is as follows:
// Prompt for remaining characters in the text box (character size)
Function textLimitCheckSj (thisArea, maxLength, SpanId ){
Var str = thisArea. value;
If (getChrLen (str, maxLength)> maxLength * 2 ){
ThisArea. value = str. substring (0, x-1 );
}
Else {
Var varss = '(remaining words:' + Math. floor (maxLength * 2-getChrLen (str, maxLength)/2) + ')';
Document. getElementById (SpanId). innerHTML = varss;
}
}
Function getChrLen (str, maxLength ){
Var realLength = 0, len = str. length, charCode =-1;
X = 0;
For (; (x <len) & (realLength <= maxLength * 2); x ++ ){
CharCode = str. charCodeAt (x );
If (charCode> = 0 & charCode <= 128)
RealLength + = 1;
Else
RealLength + = 2;
}
Return realLength;
}
?
<Asp: TextBox ID = "txtOwner_Name" runat = "server" Width = "200px" BackColor = "LightYellow"
Onkeyup = "textLimitCheckSj (this, 50, 'spowner _ name')"> </asp: TextBox> <span id = "spOwner_Name"
Style = "color: #808080"> <em> (less than 50 words) </em> </span>