[英]Checkbox onclick is not working in IE8 but working in IE9
我正在创建动态复选框,并附加onclick事件。 下面是代码:
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");
}
上面的代码在IE9上可以正常工作,但在IE8上不能正常工作。 我正在使用Jquery 1.7.1。
任何帮助将不胜感激。 谢谢..
您需要传递函数处理程序,而不是对onclick
属性的函数调用:
checkbox.onclick = testClick;
如果您使用的是jQuery,为什么不使用它呢? 那可以解决跨浏览器的问题
$(domElement).click(function(){
// do your thing here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.