参考,接受指正
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<p><span id="second">5</span>秒后回到主页 <a onclick="goback()">返回</a></p>
<script type="text/javascript">
//获取显示秒数的元素,通过定时器来更改秒数。
var second = document.getElementById("second");
var i = 5;
var timer = setInterval(function(){
clearInterval(timer);
if(second.innerHTML == 1){
window.location.href="https://www.imooc.com/code/1575";
}
else{
i--;
second.innerHTML = i;
}
},2000);
//通过window的location和history对象来控制网页的跳转。
function goback(){
window.history.go(-1);
}
</script>
</body>
</html>