[英]Checkbox onclick is not working in IE8 but working in IE9
I'm creating dynamic checkbox and attaching onclick event with that. 我正在创建动态复选框,并附加onclick事件。 Below is the code:
下面是代码:
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var checkbox = document.createElement("input");
checkbox.type = 'checkbox';
checkbox.onclick = testClick();
cell1.appendChild(checkbox);
function testClick() {
alert("Hello");
}
The above piece of code is working fine with IE9 but not with IE8. 上面的代码在IE9上可以正常工作,但在IE8上不能正常工作。 I'm using Jquery 1.7.1.
我正在使用Jquery 1.7.1。
Any help will be greatly appreciated. 任何帮助将不胜感激。 Thanks..
谢谢..
您需要传递函数处理程序,而不是对onclick
属性的函数调用:
checkbox.onclick = testClick;
If you are using jQuery, why not use it? 如果您使用的是jQuery,为什么不使用它呢? That takes care of cross browser issues
那可以解决跨浏览器的问题
$(domElement).click(function(){
// do your thing here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.