编程练习
任务
第一步: 先编写好网页布局,如下:
第二步: 获取显示秒数的元素,通过定时器来更改秒数。
第三步: 通过window的location和history对象来控制网页的跳转
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<h1>操作成功</h1>
<span id="num">5</span>秒后回到主页 <a href="" οnclick="back()">返回</a>
<script type="text/javascript">
//获取显示秒数的元素,通过定时器来更改秒数。
var e=document.getElementById("num");
var num=5;
var id=setInterval("mid()",1000);
function mid(){
num--;
if(num==0){
window.location="http://www.imooc.com";
clearInterval(id);
return;
}
e.innerHTML=num;
}
//通过window的location和history对象来控制网页的跳转。
function back(){
window.history.back();
}
</script>
</body>
</html>