注意:
- 知识点1:history 的对象方法:https://www.imooc.com/code/1149
<a href="javascript:history.back();">返回</a>
- 知识点2:
document.getElementById("seconds").innerHTML;
- 知识点3: location 的对象方法:https://www.imooc.com/code/1153
location.assign("https://www.imooc.com");
制作要求:https://www.imooc.com/code/1633
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!--先编写好网页布局-->
<sapn id="seconds">5</sapn>
<span>秒后回到主页</span>
<a href="javascript:history.back();">返回</a>
<script type="text/javascript">
var num = document.getElementById("seconds").innerHTML;
//获取显示秒数的元素,通过定时器来更改秒数。
function count() {
num--;
document.getElementById("seconds").innerHTML=num;
if (num==0){
location.assign("https://www.imooc.com");
}
}
setInterval("count()",1000);
//通过window的location和history对象来控制网页的跳转。
function back() {
window.history.back();
}
</script>
</body>
</html>