Jquery triggers the change event of the checkbox.

Source: Internet
Author: User

Reprinted from: http://blog.163.com/weizi_mm/blog/static/315544201069101132204/

this function is required in the morning. When the checkbox is selected, hidden layers are displayed. When the checkbox is deselected, the selected layers are hidden.
the initial Code is as follows:
$ (function () {
$ ("# ischange "). change (function () {
alert ("checked");
after a long time, there was no response at all. Baidu, some people pointed out that the above lines of code can run normally in Firefox and other browsers, that is, a dialog box will pop up when you select the check box or cancel the check box, but it does not run normally in IE, that is, the check box selected or canceled does not pop up immediately.
You must select or cancel the check box before clicking any place except the check box. It is said that IE will trigger the change event after the check box loses focus.
the improved code is as follows:
$ (function () {
if ($. browser. MSIE) {
$ ('input: checkbox '). click (function () {
This. blur ();
This. focus ();
$ ("# ischange "). change (function () {
alert ("checked");
supplement: after changing the value of the check box, IE is waiting to lose the focus, but the click event is triggered immediately. Therefore, the click event is used to make the check box lose the focus. This triggers the Chang event, and then the focus is re-transferred to the check box.
for radio, replace checkbox with radio.

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.