Jquery-based textarea release box limits the number of words to input (add Chinese recognition)

Source: Internet
Author: User

As follows:


The source code is as follows:
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Textarea"). keyup ();
});

Function strLenCalc (obj, checklen, maxlen ){
Var v = obj. val (), charlen = 0, maxlen =! Maxlen? 200: maxlen, curlen = maxlen, len = v. length;
For (var I = 0; I <v. length; I ++ ){
If (v. charCodeAt (I) <0 | v. charCodeAt (I)> 255 ){
Curlen-= 1;
}
}
If (curlen> = len ){
$ ("#" Upload checklen#.html ("You can also enter <strong>" + Math. floor (curlen-len)/2) + "</strong> words" ).css ('color ','');
$ ("# SubBtn"). removeAttr ("disabled ");
} Else {
$ ("#" Pipeline checklen#.html ("exceeds <strong>" + Math. ceil (len-curlen)/2) + "</strong> words" ..css ('color', '# ff0000 ');
$ ("# SubBtn"). attr ("disabled", "disabled ");
}
}
</Script>

<Textarea tabindex = "11" onkeyup = "strLenCalc ($ (this), 'checklen', 80 ); "value =" "class =" px "name =" subject "id =" subject "> </textarea>
<Span id = "checklen"> You can also enter <strong> 40 </strong> Chinese characters </span>
<Input type = "submit" id = "subBtn" value = "publish"/>

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.