Javascript倒计时器功能无法正常工作

时间:2021-12-14 21:28:01

I have developed a countdown timer function.

我开发了倒数计时器功能。

This function works fine. But the problem is it goes through the minus value too. So I want to stop the counting when its come to the 00:00:00. How can I do this.please help me?

这个功能很好。但问题是它也经历了负值。所以我想在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>

1 个解决方案

#1


1  

Replace print(); with if (time[0] >= 0) { print(); }

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

#1


1  

Replace print(); with if (time[0] >= 0) { print(); }

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