This article mainly introduced the jquery realizes the statistic input text number The method, needs the friend to be possible the reference.
HTML section:
<inputtype= "text"value= "I am the typed text"maxlength= "Ten"ID= "Detail1"/><P><spanID= "Detail1_num">0</span>/<span>10</span></P><textareaplaceholder= "Input up to 100 words"rows= "3"maxlength= "+"class= "Editdetail"ID= "Detail2" >Oh</textarea><P><spanID= "Detail2_num">0</span>/<span>100</span></P>
JS section:
1$(function(){ 2 /*Input Word Count*/3 /*Displays the number of words in the input box first when the page is loaded*/4 vartext1=$ ("#detail1"). Val ();5 varcounter1=text1.length;6$ ("#detail1_num"). Text (counter1);7 /*add trigger events to dynamically calculate the number of words in the input box*/8$ ("#detail1"). On (' Blur keyup input ',function(){9 vartext=$ ("#detail1"). Val ();Ten varCounter=text.length; One$ ("#detail1_num"). Text (counter); A }); - /*textarea Words*/ - vartext2=$ ("#detail2"). Val (); the varCounter2=text2.length; -$ ("#detail2_num"). Text (counter2); -$ ("#detail2"). On (' Blur keyup input ',function(){ - vartext=$ ("#detail2"). Val (); + varCounter=text.length; -$ ("#detail2_num"). Text (counter); + }); A});
As follows:
Because bloggers mainly do mobile development, just beginning in the mobile test because the input text will appear in the input box, the text entered in the input box in the calculation will appear error, so added an input event, this event will be in the input box in the input edge of the calculation (mainly pinyin after the completion of the confirmation of the Chinese part).
Hope to be of help to everyone.
Articles are original, reproduced please link to the form of the address of this article, thank you
Enter a quantity code using jquery statistics input and textarea text