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)">