JavaScript中定时跳转网页

JavaScript中定时跳转网页

<script>
    var demo = document.getElementById("demo"); 
     var count = 5;   
      var speed = 1000;  
       setTimeout(goIndexPage,speed);      //1秒钟之后执行   goIndexPage函数    
          function goIndexPage(){       
           count--;     
            demo.innerHTML="<a href='https://www.2678su.com'>"+count+"秒后自动跳转首页</a>";          
                  if(count <=0){           
              window.location.href = "https://www.2678su.com";  //js页面跳转     
                 }
              else{        
                 setTimeout(goIndexPage,speed);   //递归调用,自己调用自己    
               }   
                   }
                        </script>

猜你喜欢

转载自blog.csdn.net/weixin_46678271/article/details/105201610
今日推荐