[英]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.