我创建了一个可点击的表格,但是当我添加 setInterval 以每 1000 次重新加载此表格时,点击事件将停止工作。这是代码:
JQuery & Javascript 部分:
<head>
<script type="text/javascript">
//Set the timer
var myTimer = setInterval(function(){showTableContent(),1000});
//Add click
$(document).ready(function () {
var idForTableRowInfor = "#" + $("div div div table").attr('id');
$(idForTableRowInfor).click(function () {
alert('row was clicked');
});
})
//Function of showTableContent()
function showTableContent()
{
var body = plugin().USBInforArray; //Call FireBreath plugin
document.getElementById('tableInfor').innerHTML = body;
}
</script>
</head>
HTML 部分:
...
<div id="wrapper">
<div class="mainContent">
<div id="USBDetectingTable" align="center">
<table id="tableInfor" border="1">
</table>
</div> ...
当我摆脱 setInterval 一切正常,但只要我添加到该函数中,它就会停止调用点击事件。谢谢 !!!