编辑下面的代码:【加编码】
<html> <body> <p>Click the first button alert "Hello" after waiting 3 seconds.</p> <p>Click the second button to prevent the first function to execute. (You must click it before the 3 seconds are up.)</p> <button onclick="myFunction()">Try it</button> <button onclick="myStopFunction()">Stop the alert</button> <script> var myVar; function myFunction() { myVar=setTimeout(function(){alert("Hello")},3000); } function myStopFunction() { clearTimeout(myVar); } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂