Checkbox onchange事件在谷歌上ok,在ie8上不起作用了。
一番周折,測試發現勾選了以后還要點擊其他位置才會觸發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來捕獲。
IE 6 / 7 / 8 下 checkbox 不會觸發 onchange 事件,不管選中還是未選中。
所以你應該使用 onclick。