//为什么不可以直接调用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>
__innocence
慕瓜9220888