我开发了倒数计时器功能。
此功能正常。但问题是它也经历了负值。所以当它来到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>
答案 0 :(得分:1)
将print();
替换为if (time[0] >= 0) { print(); }