游泳
2015-02-25 08:20
不能运行,代码如下:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器</title> </head> <script type="text/javascript"> var num=0; function startCount() { document.getElementById('count').value=num; num=num+1; setTimeout("startCount()",1000); } var count=startCount(); </script> </head> <body> <form> <input type="text" id="count" /> </form> </body> </html>
因为没有window.onload
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器</title> </head> <script type="text/javascript"> window.onload = function() { startCount(); }; var num=0; function startCount() { document.getElementById('count').value=num; num=num+1; setTimeout("startCount()",1000); } var count=startCount(); </script> </head> <body> <form> <input type="text" id="count" /> </form> </body> </html>
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题