首页 > Web开发 > 详细

js 倒计时(转)

时间:2014-05-22 02:04:39      阅读:364      评论:0      收藏:0      [点我收藏+]

第一个(毫秒级):

bubuko.com,布布扣
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script type="text/javascript">
    var duration=9900;
    var endTime = new Date().getTime() + duration + 100;
    function interval()
    {
        var n=(endTime-new Date().getTime())/1000;
        if(n<0) return;
        document.getElementById("timeout").innerHTML = n.toFixed(3);
        setTimeout(interval, 10);
    }
    window.onload=function()
    {
        setTimeout("window.location.href=‘http://www.baidu.com‘", duration);
        interval();
    }
    </script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>等待10秒</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
             现在剩下 <span id="timeout">10.000</span> 秒后 将自动跳转        </div>
    </form>
</body>
</html>
bubuko.com,布布扣

第二个:

bubuko.com,布布扣
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">    
    <head runat="server">
        <title>
            等待10秒
        </title>
        <script type="text/javascript">
            function run() {
                var s = document.getElementById("dd");
                if (s.innerHTML == 0) {
                    window.location.href = www.baidu.com;
                    return false;
                }
                s.innerHTML = s.innerHTML * 1 - 1;
            }
            window.setInterval("run();", 1000);
        </script>
    </head>    
    <body>
        <form id="form1" runat="server">
            <div>
                请等待<span id="dd">10</span></div>
        </form>
    </body>
</html>
bubuko.com,布布扣

第三个:

bubuko.com,布布扣
<html>
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>
            counter
        </title>
        <script language="javascript" type="text/JavaScript">
            function Counter(nMax, nInterval) {
                this.maxTime = nMax;
                this.interval = nInterval;
                this.objId = "timer";
                this.obj = null;
                this.num = this.maxTime;
                this.timer = null;
                this.start = function() {
                    this.obj = document.getElementById(this.objId);
                    if (this.num > 0) setTimeout(this.run, this.interval * 1000);
                };
                this.run = function() {
                    if (myCounter.num > 0) {
                        myCounter.num--;
                        myCounter.obj.innerHTML = myCounter.num;
                        myCounter.timer = setTimeout(myCounter.run, myCounter.interval * 1000);
                    } else clearTimeout(myCounter.timer);
                };
                this.show = function() {
                    document.write("<span id=" + this.objId + ">" + this.num + "</span>");
                    this.obj = document.getElementById(this.objId);
                    //alert(this.obj.innerHTML);
                }
            }
        </script>
    </head>
    
    <body onload="myCounter.start();">
        <script language="JavaScript" type="text/JavaScript">
            var myCounter = new Counter(10, 1);
        </script>
        <p>
            现在剩下
            <script language="JavaScript" type="text/JavaScript">
                myCounter.show();
            </script>
            秒钟!
        </p>
bubuko.com,布布扣

 

js 倒计时(转),布布扣,bubuko.com

js 倒计时(转)

原文:http://www.cnblogs.com/shenyixin/p/3738700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!