要求:
1. 如果打开该页面后,如果不做任何操作则5秒后自动跳转到一个新的地址,如慕课网主页。
2. 如果点击“返回”按钮则返回前一个页面。
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p><strong>操作成功</strong></p>
<span id="time">5</span>秒后回到主页
<a href="javascript:history.back()">返回</a>
<!--通过window的history对象来控制网页的跳转。记得添加javascript:-->
<script type="text/javascript">
var count=document.getElementById("time").innerHTML;//获取显示秒数的元素
function mytimer(){//通过定时器来更改秒数。
if(count>1){
count--;
document.getElementById("time").innerHTML=count;
}
else{
window.location.assign("http://www.baidu.com/");//通过window的location对象 来控制页面跳转。
}
}
var i=setInterval("mytimer()",1000);//设置周期计时器
</script>
</body>
</html>