天天看点

关于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来捕获。

本文转自 yntmdr 51CTO博客,原文链接:http://blog.51cto.com/yntmdr/1655510,如需转载请自行联系原作者

继续阅读