倒计时结束后,因网速慢未及时跳转,秒数继续自减(-1,-2....)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自动跳转</title>
</head>
<body>
<h2>操作成功!</h2>
<p><span id="second">5</span>秒后回到主页 <a href="javascript:back();">返回</a></p>
</body>
<script type="text/javascript">
var num = document.getElementById('second').innerHTML;//获取显示秒数的元素,通过定时器来更改秒数。
function count(){
num--;
document.getElementById('second').innerHTML = num;
if(num==0){
location.assign('http://zhoushuo.me');
}
setTimeout(count,1000);
}
setTimeout(count,1000);
function back(){
window.history.back();
}
</script>
</html>