JS Real-time get the value in the input box

Source: Internet
Author: User

Getting the values in the input box in real time requires the Oninput and Onpropertychange properties to be implemented. The reason is that the Onpropertychange property is exclusive to IE, while the Oninput property supports most browsers, including IE9 and above.

Oninput and Onpropertychange failure conditions:
Oninput Event: 1. When the value is changed in the script, it does not fire; 2. When selected from the browser's automatic drop-down prompt, does not fire.

For example:

    var testinput = document.createelement (' input ');          if (' Oninput ' in testinput) {          object.addeventlistener ("input", fn,false);      } else{          object.onpropertychange = fn;      }  

Or

    var ie =!! Window. ActiveXObject;      if (IE) {          object.onpropertychange = fn;      } else{          object.addeventlistener ("input", fn,false);      }  

  Give a specific example below

<! DOCTYPE html>

Demonstrate:

JS Real-time get the value in the input box

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.