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.