Enter a quantity code using jquery statistics input and textarea text

Source: Internet
Author: User

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

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.