나는 변수에 따라 카운트 다운 시계를 표시하는 기능이 있습니다. 특정 조건에서 그것을 멈추게하는 올바른 방법은 무엇입니까? clearTimeout은 감소 함수를 중지하지 않습니다.상태가 자바 스크립트 카운트 다운 함수를 중지
function interface_vip(type){
var timeout = '';
var clock = '';
//display clock
function Decrement() {
currentMinutes = Math.floor(secs/60);
currentSeconds = secs % 60;
if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds;
secs--;
if(secs !== -1) timeout = setTimeout(Decrement,1000);
}
if (type == 1){
var mins = 20;
var secs = mins * 60;
var currentSeconds = 0;
var currentMinutes = 0;
clock = setTimeout(Decrement,1000);
}
if (type == 2){
clearTimeout(clock);
clearTimeout(timeout);
}
}
오류가 있습니다. t는 정의되지 않았습니다. –
l ook는'interface'가 JavaScript의 예약어입니다 https://mathiasbynens.be/notes/reserved-keywords#ecmascript-2 –
변수 t가 제 js에 정의되어 있습니다. 제 질문에 그것을 숫자로 바꿀 것입니다. 작동 – Adry