[JavaScript] JavaScript通过setTimeout实现一个计时器 →→→→→进入此内容的聊天室

来自 , 2019-11-17, 写在 JavaScript, 查看 104 次.
URL http://www.code666.cn/view/1eb590c1
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. var c=0;
  6. var t;
  7. var timer_is_on=0;
  8.  
  9. function timedCount()
  10. {
  11. document.getElementById('txt').value=c;
  12. c=c+1;
  13. t=setTimeout("timedCount()",1000);
  14. }
  15.  
  16. function doTimer()
  17. {
  18. if (!timer_is_on)
  19.   {
  20.   timer_is_on=1;
  21.   timedCount();
  22.   }
  23. }
  24. </script>
  25. </head>
  26.  
  27. <body>
  28. <form>
  29. <input type="button" value="Start count!" onClick="doTimer()">
  30. <input type="text" id="txt">
  31. </form>
  32. <p>Click on the button above. The input field will count forever, starting at 0.</p>
  33. </body>
  34. </html>
  35.  
  36. //javascript/7848

回复 "JavaScript通过setTimeout实现一个计时器"

这儿你可以回复上面这条便签

captcha