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