반응형
setInterval () 내에서 clearInterval ()을 호출 할 수 있습니까?
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
위의 코드가 있고 때로는 작동하지만 때로는 그렇지 않습니다. clearInterval이 실제로 타이머를 지우는 지 궁금 합니다.? monitor
작동 중일 때만 비활성화되는 이 버튼 이 있기 때문입니다 monitoring
. clearInterval
호출 된 요소 .outputRemove
를 클릭하면 또 하나 가 있습니다. 아래 코드를 참조하십시오.
//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;
});
});
그러나 다시 비활성화되기 전에 잠시 활성화되었습니다. 윌 clearInterval
로부터 프로그램을 얻을 setInterval
기능?
그래 넌 할수있어. 테스트 할 수도 있습니다.
var i = 0;
var timer = setInterval(function() {
console.log(++i);
if (i === 5) clearInterval(timer);
console.log('post-interval'); //this will still run after clearing
}, 200);
이 예에서이 타이머 i
는 5에 도달하면 지워 집니다.
참고 URL : https://stackoverflow.com/questions/16599878/can-clearinterval-be-called-inside-setinterval
반응형
'program tip' 카테고리의 다른 글
Haskell의 Prelude.read가 Maybe를 반환하지 않는 이유는 무엇입니까? (0) | 2020.08.18 |
---|---|
작업 표시 줄에서 브라우저 창 깜박임 만들기 (0) | 2020.08.18 |
Python3에서 인덱스로 dict_keys 요소에 액세스 (0) | 2020.08.18 |
jUnit의 여러 RunWith 문 (0) | 2020.08.18 |
C ++ 코드에서 UML 생성? (0) | 2020.08.18 |