Code for simulating Weibo character restrictions

Source: Internet
Author: User

This is the initial status

 

The input text is like this. Here, the rounded corner is distinguished, and two halfwidth texts are regarded as one.

 

This is beyond the limit.

 

If you click Submit, a red flashing prompt is displayed.

 

Well, the effect is like this. All of them are js .. Add a jq file ..

Here, only the prompt is exceeded, and the extra information can be truncated later .. However, the company does not need to use projects. It means that the experience is poor ~~~
Copy codeThe Code is as follows:
Var oH2 = $ ("# spetit_word"); // prompt text
Var oTextarea = $ ("# p_qa_content"); // input box
Var oButton = $ ("# bt-ico"); // button

Copy codeThe Code is as follows:
OTextarea. live ("keyup", function (){
Limit (oTextarea, 280, oH2 );
})
OButton. live ("click", function (){
If (font_count <0 | font_count = null | font_count = 140 ){
Error (oTextarea );
} Else {
Alert ('release successful! ');
}
});

Copy codeThe Code is as follows:
Var font_count;

Function WordLength (obj ){
Var oVal = obj. val ();
Var oValLength = 0;
OVal. replace (/\ n * \ s */, '') = ''? OValLength = 0: oValLength = oVal. match (/[^-~] /G) = null? OVal. length: oVal. length + oVal. match (/[^-~] /G). length;
Return oValLength
}
Function Error (obj ){
Var oTimer = null;
Var I = 0;
OTimer = setInterval (function (){
I ++;
I = 5? ClearInterval (oTimer): (I % 2 = 0? Obj.css ("background-color", "# ffffff"): obj.css ("background-color", "# ffd4d4 "));
},100 );
}
// Obj-input box to be checked, iNow-Number of words, tit-Prompt box
Function Limit (obj, iNow, tit ){
Var oValLength = WordLength (obj );
Font_count = Math. floor (iNow-oValLength)/2 );
If (font_count> = 0 ){
Tit.html ("You can also enter the <strong>" + font_count + "</strong> word ");
Return true;
} Else {
Tit.html ("exceeds <strong style = 'color: red'>" + Math. abs (font_count) + "</strong> ");
Return false;
}
Return font_count;
}

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.