请教用js实现倒计时,例如打开页面就开始90分钟的倒计时,01:30:00到00:00:00,这个倒计时的时间可以根据条件改变

解决方案 »

  1.   

    同1楼,用setinterval时间周期运行
      

  2.   

    http://www.cnblogs.com/jiangchongwei/archive/2009/09/29/1576268.html
    楼主看一下上面这种链接吧
    一个例子
      

  3.   


    <html>
    <head>
    <title>倒计时</title><script>
    var timer={};
    timer.han = null;
    timer.num = 0;
    timer.start = function(){
        timer.num = parseInt(document.getElementById("int").value) * 60 || 0;
        if(timer.han) clearInterval(timer.han);
        document.getElementById("elapse").interText = timer.num;
        timer.han = setInterval(timer.next,1000);
    };
    timer.next = function(){
        if(timer.num > 0) {
            timer.num--;
            document.getElementById("elapse").innerText = timer.num;
        }
        else{
            clearInterval(timer.han);
            alert('时间到...');
        }
    };
    timer.stop = function(){
        if(timer.han) clearInterval(timer.han);
        document.getElementById("elapse").innerText = '0';
    };
    </script>
    </head>
    <body>
    设置时间(分钟):
    <input id="int" type="text" /><br />
    <br />
    还剩 <span id="elapse">0</span>  秒<br />
    <button onclick="timer.start()">开始倒计时</button>
    <button onclick="timer.stop()">停止倒计时</button>
        
    </body>
    </html>
    这是个很简单的雏形,提供一个思路.
    小时分钟秒没有分开,你把我的timer.next函数改下就好了,这一步很简单了你自己做ok的
      

  4.   

    不知道是不是你想要的,可以自己设置过期日期!http://www.ok22.org/art_detail.aspx?id=110(可运行的实例)
      

  5.   

    想必大家在结束后没有注意要清除!setInterval事件。
    http://www.ok22.org/art_detail.aspx?id=110这个链接在结束后会清除掉而且不会消耗内存!