我有以下代码
function startTimer(time) {
var countDown = 0;
var time1 = time * 60;
x = setInterval(function() {
time2 = time1--;
if (time2 > 0) {
document.getElementById("displayTime").innerHTML = time2;
} else if (time2 == 0) {
clearInterval(x);
}
}, 1000);
}
startTimer(30)
<span id=displayTime></span>
我该如何获得这段代码中的剩余时间并将其用于暂停/恢复目的。(我计划将该值应用到函数中)。
我尝试创建了两个按钮来实现暂停和恢复,但它们不起作用。
$("#start").on("click",function(){
if (time2 < setTime){
startTimer(time2);
}
else{
startTimer(setTime);
}
});
$("#stop").on("click",function(){
clearInterval(x);
})
});
time1 = time * 60
并且改为time1 = time
,那么它对我来说就像预期的一样工作。 - john Smith