IE onchange event-triggered bug and solution tutorial

Source: Internet
Author: User

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

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.