2014-05-14 117 views
0

我已經實現了JQuery倒計時器(jquery.lwtCountdown-1.0.js)。在不同的機器和相同的機器不同的瀏覽器中,我面臨計時器的延遲。有時總共15分鐘需要40-50秒延遲。 javascript邏輯定義如下:JQuery倒計時定時器延遲

<script type="text/javascript" > 
    var Timer; 

    function CreateTimer(TimerID, Time){ 
      Timer = document.getElementById(TimerID); 
    TotalSeconds = Time; 

    UpdateTimer(); 
    window.setTimeout("Tick()", 1000); 
} 
function Tick() { 
    TotalSeconds -= 1; 
    if(TotalSeconds>=0){ 
     UpdateTimer(); 
     window.setTimeout("Tick()", 1000); 
    }else{ 
      // NO TIME THEN LOGOUT 
        //   alert(SUCCESS_LOGOUT); 
    } 
} 
function UpdateTimer() { 
     var Seconds = TotalSeconds; 

    var Days = Math.floor(Seconds/86400); 
    Seconds -= Days * 86400; 

    var Hours = Math.floor(Seconds/3600); 
    Seconds -= Hours * (3600); 

    var Minutes = Math.floor(Seconds/60); 
    Seconds -= Minutes * (60); 


    var TimeStr = "" +((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)+"<b>" 
    Timer.innerHTML = TimeStr; 
} 

function LeadingZero(Time) { 
    return (Time < 10) ? "0" + Time : + Time; 
} 

</script> 

上面的代碼是javascript的。我找不到任何計時器延遲的解決方案。 有什麼遺漏嗎?

在此先感謝!

回答

0

有兩個問題與您的代碼:

1. window.setTimeout("Tick()", 1000); here you are passing a string you need to 
             pass a function 
2. you need a global variable for TotalSeconds 

我不知道這段代碼做什麼,但是這裏有一個工作DEMO

+0

1.傳字符串不影響功能是調用。它在1000毫秒後被調用。 2.是TotalSeconds已全局定義。 我認爲可能有某些與機器進程或瀏覽器的進程有關的延遲時間。 –