1 <html lang="en"> 2 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 7 <title>一次定时器</title> 8 </head> 9 10 <body> . 11 < Button ID = "BTN" > 3 seconds after release </ Button > 12 is < Button ID = "btn1" > Stop </ Button > 13 is < Script > 14 the window.onload = function () { 15 // . 1. acquiring the tag 16 var BTN = document.getElementById ( ' BTN ' ); . 17 var btn1 = document.getElementById ( 'btn1 '); 18 var timer = null; 19 btn.onclick = function() { 20 clearTimeout(timer) 21 timer = setTimeout(function() { 22 alert('3秒释放') 23 }, 3000) 24 } 25 btn1.onclick = function() { 26 clearTimeout(timer) 27 } 28 } 29 </script> 30 </body> 31 32 </html>