我正在完成一个番茄钟时钟,我一切正常,直到计时器变为零,这是它应该切换到中断计时器,但它保持为零。任何帮助是极大的赞赏。
http://codepen.io/sammyb123/pen/QyQaPr
function start(){
$("#start").addClass("disabled");
$("#myreset").addClass("disabled");
var secs = Number("59");
var minutes = document.getElementById('mytimer').innerHTML;
var num = minutes.split("");
var min = document.getElementById("sessiontime").innerHTML;
var 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 (min === 0 && secs === 00){
var x = document.getElementById("arrownumid").innerHTML;
mybreak(x);
}
},1000);
}
function mybreak(bt){
var b = bt;
var secs = Number("59");
//document.getElementById("mytimer").innerHTML = mybt;
min--;
startBreak = setInterval(function(){
secs--;
if(min > -1){
if(secs > 9){
document.getElementById("mytimer").innerHTML = b + ":" + secs;
}else if(secs > 0 && secs < 10){
secs = "0" + secs;
document.getElementById("mytimer").innerHTML = b + ":" + secs;
}else if(secs === 0){
document.getElementById("mytimer").innerHTML = "Break Over";
}
}
}, 1000);
}
谢谢
答案 0 :(得分:1)
我认为你的变量
var secs = Number("59");
var minutes = document.getElementById('mytimer').innerHTML;
应该在函数()开始之外声明..因为它们可以在mybreak函数中编辑!
答案 1 :(得分:1)
在start函数之外声明变量(min,secs和minutes)之后确定 ,只需将最后一个if放在setInterval函数
中所以反过来这部分
},1000);
}else if (min === 0 && secs === 00){
var x = document.getElementById("arrownumid").innerHTML;
mybreak(x);
}
就是这样:
}else if (min === 0 && secs === 00){
var x = document.getElementById("arrownumid").innerHTML;
mybreak(x);
},1000);
}
答案 2 :(得分:0)
仔细查看下面的代码,您将了解代码有什么问题。
function hms(t, out){
var h = Math.floor(t/3600), m = Math.floor((t-(h*3600))/60), s = Math.round(t-(h*3600+m*60));
if(h < 10)h = '0'+h;
if(m < 10)m = '0'+m;
if(s < 10)s = '0'+s;
var r = h+':'+m+':'+s;
if(out.innerHTML){
out.innerHTML = r;
}
else if(out.value){
out.value = r;
}
else{
return r;
}
}
function pomodoro(outputElement, hours, minutes, seconds, doneMsg){
var h = hours || 0;
var m = minutes || 0;
var s = seconds || 0;
var t = h*3600+m*60+s;
var d = doneMsg || 'Break Over';
hms(t, outputElement);
var timer = setInterval(function(){
hms(--t, outputElement);
if(t === 0){
if(outputElement.innerHTML){
outputElement.innerHTML = d;
}
else{
outputElement.value = d;
}
clearInterval(timer);
}
}, 1000);
}
// normal use
pomodoro(document.getElementById('mytimer'), 0, 0, 10);
// or
pomodoro(document.getElementById('mytimer'), 1);
// or
pomodoro(document.getElementById('mytimer'), 0, 25);
// or
pomodoro(document.getElementById('mytimer'), 1, 25, 32, 'Your Break is Over Sir');
// abnormal use
pomodoro(document.getElementById('mytimer'), 1, 0, 99);