1, onchange
The onchange event is triggered when the content of the domain changes. Supported labels <input type= "text", <textarea>, <select>,<keygen>. NOTE: Triggers when the value of the element has changed and loses focus (the value of two times does not fire). Defect: The value of DOM changed by JS code will not be triggered, the change in JS code to call its change
function ()or adjust the. Change () method. Js:
1 |
< input type="text" id="cash" onchange="function()"> |
Jquery:
1 |
$("#cash").change(function(){}); |
2, Onpropertychange
The onpropertychange is triggered in real time, triggering events as the attributes of the element change. Does not fire when an element is disable=true. Defects: Only under IE support, other browsers do not support, with oninput to solve. Js:
1 |
< input type="text" id="cash" onpropertychange="functionName()"> |
3, Oninput
Oninput is triggered when the value of <input> or <textarea> changes, and does not need to wait until the element loses focus and is in real time. It is a HTML5 event that can be used to detect the value of a text class input box. Defect: Modifying a value from a script does not trigger an event. Selecting a value from the browser drop-down prompt does not trigger. IE9 below are not supported, so IE9 can be replaced with Onpropertychange events below. Solution: Change the DOM value by JS Code does not trigger, solve in the JS code changed the value of the call its oninput
functionname ()Method. Js:
1 |
< input type="text" oninput="functionName()"> |
Jquery:
1 |
$("#cash").on(‘input propertychange‘,functionName); |
4, AddEventListener
AddEventListener () is used to add an event method to the specified element. Use RemoveEventListener () to remove the added event method. IE9 below is not supported, replace with Attachevent.
Syntax: element. AddEventListener (event, function, Usecapture)
---------------------------------------------------
How to allow input to enter only numbers:
Onkeyup= "Value=value.replace (/[^\d]/g, ')"
Triggering events about the change of input content