<!DOCTYPE html> <html> <body> <h1>Window 对象</h1> <h2>setInterval() 和 clearInterval() 方法</h2> <p id="demo"></p> <button onclick="myStop()">停止计时</button> <script> const myInterval = setInterval(myTimer, 1000); function myTimer() { const date = new Date(); document.getElementById("demo").innerHTML = date.toLocaleTimeString(); } function myStop() { clearInterval(myInterval); } </script> </body> </html>