qq_一二三亖_nrER57
2018-12-14 16:23
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p><b>操作成功</b></p>
<p><span id='num1'>5</span>秒后回到主页 <a href="history()">返回</a></p>
<script type="text/javascript">
var num= document.getElementById('num1').innerHTML
//获取显示秒数的元素,通过定时器来更改秒数。
console.log(num)
function number(){
num--;
ocument.getElementById('num1').innerHTML=num
if(num==0){
location.assign("http://www.imooc.com");
}
etTimeout('number()',1000)
} s
etTimeout('number()',1000)
//通过window的location和history对象来控制网页的跳转。
function history(){
window.history.back()
}
</script>
</body>
</html>
就我看来,你的代码有以下几个问题。
1:17行 document写错了,ocument.
2:21,22行,setTimeout写成了etTimeout
3:<a href="history()">返回</a></p> 这一句里,虽然JS href标签可以接函数,语法是href="javascript:function()",但是这种写法不推荐:推荐写法:
href="http://www.imooc.com" onclick="history()"。
4.你的number()函数内,location.assign("http://www.imooc.com"); 改为window.location.assign("http://www.imooc.com");
没有上一页吧
JavaScript进阶篇
469067 学习 · 22582 问题
相似问题