Reference Blog: http://www.cnblogs.com/lhb25/archive/2012/11/30/oninput-and-onpropertychange-event-for-input.html
$ (function () {var limitsum = 140;//Limit number of wordsvar showwords = $ ("#showWords");//text box gets focus and event when the focus is lost$ ("#txt"). focus (function () {if ($ (this). val () = = "") {showwords.show (). HTML ("can also enter" + "" +limitsum+ "" + "Words"). Find ("span"). CSS ({" font-size": "20px","COLOR": "Green" }); }}). blur (function () {if ($ (this). val () = = "") {showwords.hide (); } });//Text input change$ ("#txt"). On ("Input PropertyChange", function () {var Inum=math.ceil ($ (this). Val ())/2);//math function rounding up, here is the number of characters, if you want to count bytes, here can be commentedif (inum>limitsum) {showwords.html ("more than" + "+" + (Inum-limitsum) + "+" characters "). Find ("span"). CSS ({" font-size": "20px","COLOR": "Red" }); }else{showwords.html ("You can also enter" + "" + (Limitsum-inum) + "+" characters "). Find ("span"). CSS ({" font-size": "20px","COLOR": "Green" }); } });});//The function that the input content is text or letterfunction GetLength (str) {return String (str). replace (/[^\x00-\xff]/g, ' AA '). length;};
jquery Imitation Sina Weibo limit text box word count