我怎么能循环我的计时器?

时间:2012-05-29 10:19:28

标签: javascript loops timer countdown

我已经尝试了半天来循环这个倒计时功能。我不想创造不同的倒计时。我该如何循环呢?请注意,这是一个倒数计时器,间隔为1秒。我的网站在http://jian.comoj.com/

<script type="text/javascript">

    setInterval('countdown()',1000);

    function countdown(){

        var now = new Date();

        var unix_now= now.getTime()/1000;

        unix_now= Math.floor(unix_now);


        var sec = <?php echo $end_time[0]; ?> - unix_now;


        if(sec<=0){
            clearInterval(stop);

        }



        var min = Math.floor(sec / 60);
        var hour = Math.floor(min / 60);

        hour %= 24;
        min %= 60;
        sec %= 60;

        document.getElementById(0).innerHTML= hour+":"+min+":"+sec;


    }

    setInterval('countdown1()',1000);

    function countdown1(){

        var now = new Date();

        var unix_now= now.getTime()/1000;

        unix_now= Math.floor(unix_now);


        var sec = <?php echo $end_time[1]; ?> - unix_now;


        if(sec<=0){
            clearInterval(stop);

        }



        var min = Math.floor(sec / 60);
        var hour = Math.floor(min / 60);

        hour %= 24;
        min %= 60;
        sec %= 60;

        document.getElementById(1).innerHTML= hour+":"+min+":"+sec;


    }

    setInterval('countdown2()',1000);

    function countdown2(){

        var now = new Date();

        var unix_now= now.getTime()/1000;

        unix_now= Math.floor(unix_now);


        var sec = <?php echo $end_time[2]; ?> - unix_now;


        if(sec<=0){
            clearInterval(stop);

        }



        var min = Math.floor(sec / 60);
        var hour = Math.floor(min / 60);

        hour %= 24;
        min %= 60;
        sec %= 60;

        document.getElementById(2).innerHTML= hour+":"+min+":"+sec;


    }

</script>

1 个答案:

答案 0 :(得分:0)

您还需要将setInterval放在倒计时功能中。像递归呼叫一样。