Step 1: The following is the core code, which can be referenced on the page or encapsulated.
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
Function textLimitCheck (thisArea, maxLength, SpanId)
{
If (thisArea. value. length> maxLength)
{
ThisArea. value = thisArea. value. substring (0, maxLength );
ThisArea. focus ();
}
/* Write back the span value. Enter the text currently */
Var varss = '(remaining words:' + (maxLength-thisArea.value.length) + ')';
Document. getElementById (SpanId). innerHTML = varss;
}
</Script>
Step 2: apply this function to the text box
Copy codeThe Code is as follows:
<Asp: TextBox ID = "txtOwner_Name" runat = "server" Width = "250px" MaxLength = "50" onkeyup = "textLimitCheck (this, 50, 'spowner _ name ') "BackColor =" Info "> </asp: TextBox>
<Span id = "spOwner_Name" style = "color: gray"> <em> (less than 50 words) </em> </span>