无穷循环中的计时

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var c=0
  5. var t
  6. function timedCount()
  7. {
  8. document.getElementById('txt').value=c
  9. c=c+1
  10. t=setTimeout("timedCount()",1000)
  11. }
  12. </script>
  13. </head>
  14.  
  15. <body>
  16. <form>
  17. <input type="button" value="开始计时!" onClick="timedCount()">
  18. <input type="text" id="txt">
  19. </form>
  20. <p>请点击上面的按钮。输入框会从 0 开始一直进行计时。</p>
  21. </body>
  22.  
  23. </html>