HTML5 input event detection input box changes

Source: Internet
Author: User

HTML5 input event detection input box changes
Previously, I used the change event to monitor whether the content of the input box has changed. It is triggered only when the input box loses focus. I did not expect that there is an input event in html5. As long as the content of the input box changes, it will be triggered immediately, since we don't need such a good thing, let's introduce it to you: if there is such a simple to extreme input box on our page: 1 <input type = "text"> now we use jquery to bind an input event to it, as shown below:

1 $ ("input: text "). bind ("input propertychange", function () {2 3 console. log ($ (this ). val (). length); // print the character length of the input box 4 5 });

 

In this way, as long as the content of the input box changes, the length of the character string will be printed immediately. Note that the input event is html5 and cannot be supported in IE9 or earlier versions. Therefore, the propertychange event must be used instead. In addition to listening to the content changes of the input: text element, the input: password, input: search, and textarea elements can also be monitored. The html binding method is as follows: 1 <input type = "text" oninput = "onInput (event)" onpropertychange = "onPropertyChange (event)">

Related Article

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.