倒计时自动跳转路径

    1.第一种方法:

 1 <html> 
 2 <head><title></title> 
 3 <script language='javascript' type='text/javascript'> 
 4 var secs =5; //倒计时的秒数 
 5 var URL ; 
 6 function Load(url){ 
 7 URL =url; 
 8 for(var i=secs;i>=0;i--) 
 9 { 
10 window.setTimeout('doUpdate(' + i + ')', (secs-i) * 1000); 
11 } 
12 } 
13 function doUpdate(num) 
14 { 
15 document.getElementById('ShowDiv').innerHTML = '将在'+num+'秒后自动跳转到 脚本之家' ; 
16 if(num == 0) { window.location=URL; } 
17 } 
18 </script> 
19 </head> 
20 <body> 
21 <div id="ShowDiv"></div> 
22 <script language="javascript"> 
23 Load("http://www.jb51.net"); 
24 </script> 
25 </body> 
26 </html> 
View Code

 2.第二中方法:

  使用setTimeout函数实现定时跳转(如下代码要写在body区域内)

 

    <script type="text/javascript"> 
    //3秒钟之后跳转到指定的页面 
    setTimeout(window.location.href='http://www.daimajiayuan.com',3); 
    </script> 

 

3.html代码实现,在页面的head区域块内加上如下代码:

 

    <!--5秒钟后跳转到指定的页面--> 
    <meta http-equiv="refresh" content="5;url=http://www.daimajiayuan.com" /> 

 

4.稍微复杂点,多见于登陆之后的定时跳转:

  

    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>js定时跳转页面的方法</title> 
    </head> 
    <body> 
    <script type="text/javascript"> 
    var t=10;//设定跳转的时间 
    setInterval("refer()",1000); //启动1秒定时 
    function refer(){  
        if(t==0){ 
            location="http://www.daimajiayuan.com/sitejs-17251-1.html"; //#设定跳转的链接地址 
        } 
        document.getElementById('show').innerHTML=""+t+"秒后跳转到代码家园"; // 显示倒计时 
        t--; // 计数器递减 
        //本文转自: 
    } 
    </script> 
    <span id="show"></span> 
    </body> 
    </html> 

 

  

 

posted @ 2017-04-17 13:47  直到无限宇宙  阅读(283)  评论(0)    收藏  举报