<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<p><span id="time">5</span>秒后回到主页 <a href="javascript:window.history.back();">返回</a></p>
<script type="text/javascript">
//获取显示秒数的元素和倒数开始数
var time = document.getElementById("time");
var num = parseInt(time.innerHTML);
//添加定时器,实现倒数效果
var timer = setInterval(function(){
num--;
time.innerHTML = num;
//每次开启一次定时器之后要关闭一次,防止倒数越来越快
clearInterval(timer);
if(num == 0){
window.history.back();
}
},1000);
</script>
</body>
</html>