运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Window Object</h1> <h2>The clearTimeout() Method</h2> <p>Click the button to prevent the timeout to execute. (You have 3 seconds).</p> <h2 id="demo"></h2> <button onclick="myStopFunction()">Stop it</button> <script> const myTimeout = setTimeout(myGreeting, 3000); function myGreeting() { document.getElementById("demo").innerHTML = "Happy Birthday!" } function myStopFunction() { clearTimeout(myTimeout); } </script> </body> </html>