无限循环中的计时事件
- <!DOCTYPE html>
- <html>
- <body>
- <button onClick="setInterval(myCounter, 1000)">启动计数器</button>
- <p id="demo">点击上面的按钮,我会永远计数。</p>
- <script>
- var c = 0;
- function myCounter() {
- document.getElementById("demo").innerHTML = ++c;
- }
- </script>
- </body>
- </html>