我开发了一个倒计时函数。
这个函数工作得很好。但问题是它会继续进行到负数。所以当它到达 00:00:00
时,我想停止计数。请问我该怎么做?
Javascript
function initCountdown() {
if( seconds == 0 && minutes == 0 && hours == 0 ){
clearInterval( interval ); }
if (seconds < 10) {
outputElement.innerHTML = hours + ": " + minutes + ": " + "0" + seconds + " ";
} else {
outputElement.innerHTML = hours + ": " + minutes + ": " + seconds + " "; }}
function count(){
time[2]--;
if (time[2] == -1) {
time[1]--;
time[2] = 59
}
if (time[1] == -1) {
time[0]--;
time[1] = 59
}
print();
}
var outputElement = document.getElementById('demo');
var time = document.getElementById("picker-dates1").value;
time = time.split(':'); }
HTML
<input type = "text" id = "picker-dates1"/>
<P id="demo"></p>
clearInterval
函数的目的是什么?它会重置时钟吗? - PaulShovanoutputElement.innerHTML = hours + ": " + minutes + ": " + seconds + " "; }}
中有一个多余的括号。 - abhiox