bigloop=setInterval(function () {
var checked = $('#status_table tr [id^="monitor_"]:checked');
if (checked.index()===-1 ||checked.length===0 || ){
bigloop=clearInterval(bigloop);
$('#monitor').button('enable');
}else{
(function loop(i) {
//monitor element at index i
monitoring($(checked[i]).parents('tr'));
//delay of 3 seconds
setTimeout(function () {
//when incremented i is less than the number of rows, call loop for next index
if (++i < checked.length) loop(i);
}, 3000);
}(0)); //start with 0
}
}, index*3000); //loop period
Tôi có mã ở trên và đôi khi nó hoạt động, đôi khi nó không. Tôi đang tự hỏi nếu clearInterval thực sự xóa bộ đếm thời gian ?? bởi vì có monitornút này sẽ chỉ bị vô hiệu hóa khi nó đang monitoringhoạt động. Tôi có một cái khác clearIntervalkhi một phần tử được gọi .outputRemoveđược nhấp vào. Xem mã bên dưới:
//remove row entry in the table
$('#status_table').on('click', '.outputRemove', function () {
deleted= true;
bigloop= window.clearInterval(bigloop);
var thistr=$(this).closest('tr');
thistr.remove();
$('#monitor').button('enable');
$('#status_table tbody tr').find('td:first').text(function(index){
return ++index;
});
});
Nhưng nó đã được kích hoạt trong một thời gian trước khi nó bị vô hiệu hóa trở lại. Sẽ clearIntervallấy chương trình ra khỏi setIntervalchức năng?
lỗi đánh máy của opps. tôi đã có một hàm
—
yvonnezoe
clearloop(loopname)có chứa clearIntervalnhưng để đơn giản hóa nó, tôi đã thay đổi nó trực tiếp trong đoạn mã trên.
loopnameở đoạn mã thứ hai? Đó là gì?