我要吃冰激凌
2016-03-10 23:57
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p>
<p><span id="second">5</span>秒后返回主页 <a href="http://www.baidu.com">返回</a></p>
<script type="text/javascript">
var num=5;
var i;
function myTime(){
num--;
document.getElementById("second").innerHTML=num;
if(num=0){
clearTimeout(i-1);
window.location.href = "http://www.imooc.com/";
}
i=setTimeout("myTime()",1000)
}
setTimeout("myTime()",1000)
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html>
第18行 if=0改成if==0
=是赋值的意思
==是等于的意思
如图 第18行 中的 if条件 是赋值语句 改成 == 于
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title><meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p>
<p><span id="second">5</span>秒后返回主页 <a href="http://www.baidu.com">返回</a></p>
<script type="text/javascript">
var num=5;
var i;
function myTime(){
num--;
document.getElementById("second").innerHTML=num;
if(num==0){//注意这里
clearInterval(i);
window.location.href = "http://www.imooc.com/";
}
// i=setTimeout("myTime()",1000)
}
i=setInterval(myTime,1000)
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
JavaScript进阶篇
469244 学习 · 22584 问题
相似问题