Today I encountered a bug in the Internet Explorer onchange event. This bug exists in all Internet Explorer versions (6, 7, 8). I don't know if it's a bug, or did I design it like this on purpose? Let's take a look at the reproduction process of the IE onchange event:
Add onchange events to controls such as input, for example, input checkbox (radio), and click Select under IE. the onchange event is not triggered, the onchange event can be triggered only when the focus is lost again (any place on the page is clicked), while the onchange event can be triggered when the checkbox is clicked in Firefox ~
Bug reproduction code
<Html>
<Head> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> IE onchange event bug </title> <Body>
<Input type = "checkbox" value = "1" onchange = "alert (this. value);" id = "demo1"/>
<Label for = "demo1"> demo1 </label>
<Input type = "checkbox" value = "2" onchange = "alert (this. value);" id = "demo2"/>
<Label for = "demo2"> demo2 </label>
</Body>
Solution
Binding a change event in jQuery1.4.2 can be completely solved, but binding a change event in jQuery1.3.2 cannot. We can bind a change event through the click event.
If you are not afraid of trouble and do not mind binding two events, you can use the onpropertychange event that comes with IE to bind the change event. It is possible to test the damage caused by broken bridges, however, this method is bound to two change events in IE. This method is not recommended. If it is checkbox or radio, use the click event to handle it.
Source: http://www.js8.in/541.html