//为什么不可以直接调用count()函数呢? 如果直接调用的话,就出现上面的错误。
//源码如下:
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<script>
secs = 5;
function count()
{
document.getElementById("sec").innerHTML = secs;
//document.getElementById("sec").value = secs;
--secs;
if(secs == 1)
location.replace("http://www.imooc.com");
setTimeout(count, 1000);
}
count();
//setTimeout(count, 0); 这样使用就没问题了!
</script>
<span><i id="sec">5</i>秒后返回主页<a href="https://www.baidu.com">返回</a></span>
</body>
</html>
1 回答
已采纳
![?](http://img1.sycdn.imooc.com/626b8bf50001a3be09700970-100-100.jpg)
__innocence
TA贡献313条经验 获得超208个赞
1、定义变量敢不敢使用关键字var secs = 5;
2、敢不敢把JavaScript写在文档下面?
<!DOCTYPE html> <html> <head> <title>浏览器对象</title> <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> </head> <body> <!--先编写好网页布局--> <h2>操作成功</h2> <span><i id="sec">5</i>秒后返回主页<a href="https://www.baidu.com">返回</a></span> <script> var secs = 5; function count() { document.getElementById("sec").innerHTML = secs; //document.getElementById("sec").value = secs; --secs; if(secs == 1) location.replace("http://www.imooc.com"); setTimeout(count, 1000); } count(); //setTimeout(count, 0); 这样使用就没问题了! </script> </body> </html>
添加回答
举报
0/150
提交
取消