JQuery倒数计时器延迟了

时间:2014-05-14 15:59:45

标签: javascript jquery html timer countdown

我已经实现了JQuery Countdown Timer(jquery.lwtCountdown-1.0.js)。面对不同机器和同一机器不同浏览器的计时器延迟。有时总共需要40-50秒延迟15分钟。 javascript逻辑定义如下:

<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。我无法找到延迟定时器的任何分辨率。 有什么遗失的吗?

提前致谢!!!

1 个答案:

答案 0 :(得分: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