需求来自于csdn问答,可以利用这个原理做秒杀抢单外挂。
代码示例如下:
<html> <head> <meta charset="utf-8"/> <script type="text/javascript"> var count = 10; var sh; function counter(){ sh = setInterval(jishi,1000); } function jishi(){ var btn = document.getElementById("btn"); btn.innerHTML = "倒计时"+(--count)+"秒"; if(count == 0){ btn.disabled = false; btn.innerHTML = "开始点击"; clearInterval(sh); btn.onclick = function(){ var result = document.getElementById("result"); setInterval(function(){ //执行点击操作 result.innerHTML = "您点击了:"+(count++)+"次"; },100); }; btn.click(); } } window.onload = counter; </script> </head> <body> <button id="btn" disabled="disabled">倒计时10秒</button> <span id="result"></span> </body> </html>
时间: 2024-10-02 13:00:00