<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<p>
<span id="countdown">5</span> 秒后回到主页
<a href="#tag1" onclick="goBack()">返回</a>
<a name="tag1"></a>
</p>
<script type="text/javascript">
//获取显示秒数的元素,通过定时器来更改秒数。
var num = 5;
function countdownTimer(){
num--;
document.getElementById("countdown").innerHTML = num;
if(0==num)
{
num = 5;
location = "http://www.imooc.com";
}
}
var int = setInterval(countdownTimer,1000);
//通过window的location和history对象来控制网页的跳转。
function goBack(){
clearTimeout(int);
history.back();
}
</script>
</body>
</html>