JS 10 seconds Countdown

Source: Internet
Author: User

The first one:

<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);}elseclearTimeout(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><body onload="myCounter.start();"><script language="JavaScript"type="text/JavaScript">var myCounter=newCounter(10,1);</script><p>现在剩下<script language="JavaScript"type="text/JavaScript">myCounter.show();</script>秒钟!</p>

The second: It's a very moderate countdown, and I use this.

请等待<span id="dd">10</span>秒<script type="text/javascript">function run(){    vars = document.getElementById("dd");    if(s.innerHTML == 0){        window.location.href=‘www.baidu.com‘;        returnfalse;    }    s.innerHTML = s.innerHTML * 1 - 1;}window.setInterval("run();", 1000);</script>

The third: millisecond-level, more tense:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    <script type="text/javascript">    <!--    varduration=9900;    varendTime = newDate().getTime() + duration + 100;    function interval()    {        varn=(endTime-newDate().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>"http://www.w3.org/1999/xhtml">"server">    <title>等待10秒</title><body>    <form id="form1"runat="server">        <div>             现在剩下 <span id="timeout">10.000</span> 秒后 将自动跳转        </div>    </form></body>

JS 10 seconds Countdown

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.