如何改变文本时倒数零



你好,我的倒计时不停止在零,我需要改变我的测试时倒计时为零,这个倒计时开始后,我需要替换倒计时为零后的值.....$countdown = 50

function startTimer(duration, display) {
var start = Date.now(),
    diff,
    minutes,
    seconds;
function timer() {
    // get the number of seconds that have elapsed since 
    // startTimer() was called
    diff = duration - (((Date.now() - start) / 1000) | 0);
    // does the same job as parseInt truncates the float
    minutes = (diff / 60) | 0;
    seconds = (diff % 60) | 0;
    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
    display.textContent = minutes + ":" + seconds; 
    if (diff <= 0) {
        // add one second so that the count down starts at the full duration
        // example 05:00 not 04:59
        start = Date.now() + 1000;
    }
};
// we don't want to wait a full second before the timer starts
timer();
setInterval(timer, 1000);
}
window.onload = function () {
var fiveMinutes = <?php echo $countdown?>
    display = document.querySelector('#time');
startTimer(fiveMinutes, display);
  };

PHP In body

     if ($countdown>3){
        echo "Next Submit: Wait <span id='time'></span>";
    }else{
    echo "Next Submit: READY....!";
    }

您应该将setInterval()调用保存为一个变量。

var myTimer = setInterval();

这样以后就可以引用它了。然后,你可以在你的函数内调用来检查某个条件(在你的情况下,当倒计时达到0时),然后使用clearInterval()来结束计时器。

主题涵盖clearInterval()

最新更新