Er. It seems that the log has not been written for a long time .. Recently busy every day to worry about... Today, we have to empty a backup of the tips used in the project .. If you have seen it, please ignore it .. I am a front-end kitten ~~~
There is such a thing in the company's project that everyone in Weibo understands ~~
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 ~~~
VaR oh2 = $ ("# spetit_word"); // The prompt text var otextarea = $ ("# p_qa_content "); // input box var obutton = $ ("# Bt-ICO"); // button
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! ');}});
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 <strong>" + font_count + "</strong>"); Return true ;} else {tit.html ("exceeds <strong style = 'color: red'>" + math. ABS (font_count) + "</strong> word"); Return false;} return font_count ;}