2015-10-06 21 views
0

你好我的倒計時不停止在零我需要改變我的測試,當倒計時到零,這個倒計時開始零值後,我需要在倒計時後替換值爲零..... $倒計時= 50如何改變文本時coundown零

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在身體

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

你的問題還不清楚。什麼是錯誤? – Matheno

回答

0

您應該保存setInterval()調用的變量。

var myTimer = setInterval();

這樣你可以在以後引用它。然後,您可以在功能中調用某個條件(在倒數到達0的情況下),然後使用clearInterval()來結束定時器。

Topic covering clearInterval()

+0

現在它不顯示實時更新 –

+0

需要看到清除間隔的代碼來幫助。確保在完成更新後清除間隔。 – Chris