js定时跳转

在项目中有时会用到定时跳转,自己收藏了一个比较好用的###

js写的,不依赖jQuery

    <script type="text/javascript">
          function countDown(secs,surl){
            var jumpTo = document.getElementById('jumpTo');
            jumpTo.innerHTML=secs; 
            if(--secs>0){    
              setTimeout("countDown("+secs+",'"+surl+"')",1000);    
            }else{      
              location.href=surl;    
            }    
          }    
        </script>

        <span id="jumpTo">5</span>秒后自动跳转到<a href='/'>首页</a> 
        <script type="text/javascript">countDown(5,'/');</script> 

个人博客地址:http://www.hioop.net

posted @ 2014-11-28 17:36  hioop  阅读(357)  评论(0编辑  收藏  举报

Copyright © hioop.net