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>