Example code for Javascript to display the remaining words of a real string

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.