js定时跳转

时间:2021-05-11 17:48:13

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

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