There is such a character restriction in a company project. Everyone who wants to use Weibo understands that this is the initial state.
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 ~~~
The Code is as follows:
Var oH2 = $ ("# spetit_word"); // prompt text
Var oTextarea = $ ("# p_qa_content"); // input box
Var oButton = $ ("# bt-ico"); // button
The 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! ');
}
});
The 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"+ Font_count +"Word ");
Return true;
} Else {
Tit.html ("exceeds"+ Math. abs (font_count) +"Word ");
Return false;
}
Return font_count;
}