JavaScript倒计时器函数无法正常工作

3

我开发了一个倒计时函数。

这个函数工作得很好。但问题是它会继续进行到负数。所以当它到达 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 函数的目的是什么?它会重置时钟吗? - PaulShovan
我没有看到你从time []中定义秒、分钟或小时的位置。 - Charles Shiller
outputElement.innerHTML = hours + ": " + minutes + ": " + seconds + " "; }} 中有一个多余的括号。 - abhiox
你的脚本不起作用(我在Mozilla上尝试过了)。 - Vivek Gupta
1个回答

1
print(); 替换为 if (time[0] >= 0) { print(); }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接