关于IE下Checkbox标签的onchange事件兼容

今天写一个全选功能,在chrome和firefox下测试都正常实现效果,到了ie下死活没效果.

一番周折,测试发现勾选了以后还要点击其他位置才会触发onchange事件.

用度娘查询了一下.

有下面两种解决方式:

用onclick事件代替

1、<input type=checkbox onclick="alert(this.value)" value=huerreson>

用onpropertychange事件代替
2、<input type=checkbox onpropertychange="alert(this.value)" value=huerreson>

IE下,当一个HTML元素的属性改变的时候,都能通过 onpropertychange来捕获。

 

原文地址:https://www.cnblogs.com/fumj/p/2558959.html