时钟工作直到它变为零,这是它应该启动中断计时器的地方。问题是它变为零然后开始以负数倒计时。这是具有该代码的函数。顺便说一句,我的间隔为100,所以在测试时钟时我不需要等待很长时间。
//This function is the culprit
function start(){
$("#start").addClass("disabled");
$("#myreset").addClass("disabled");
var secs = Number("59");
var min = document.getElementById("sessiontime").innerHTML;
min = min-=1;
if(min > -1){
startcounter = setInterval(function(){
secs--;
if(secs > 9){
document.getElementById("mytimer").innerHTML = min +":"+ secs;
} else if(secs >=0 && secs < 10){
secs = "0"+secs;
document.getElementById("mytimer").innerHTML = min +":"+ secs;
} else if(secs < 0){
min--;
secs = 59;
} else if(secs === 0 && min === 0){
clearInterval(startcounter);
var x = document.getElementById("arrownumid").innerHTML;
mybreak(x);
}
},100);
}
}
答案 0 :(得分:0)
我实际上已经弄清楚了,可能不是最有效的,但它会做它应该做的事情。感谢您抽出宝贵时间提供帮助。
function start(){
$("#start").addClass("disabled");
$("#myreset").addClass("disabled");
var secs = Number("59");
var min = document.getElementById("sessiontime").innerHTML;
min = min-=1;
if(min>=0){
startcounter = setInterval(function(){
secs--;
if(secs > 9){
document.getElementById("mytimer").innerHTML = min +":"+ secs;
} if(secs >0 && secs < 10){
secs = "0"+secs;
document.getElementById("mytimer").innerHTML = min +":"+ secs;
} if(secs ===0 && min >0){
min--;
secs = 59;
}
else if(min ===0 && secs ===0){
document.getElementById("beep").play();
stop(startcounter);
clearInterval(startcounter);
var x = document.getElementById("arrownumid").innerHTML;
mybreak(x);
}
},1000);
}
}