<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title> Micomo </title> </head> <body> <div> <p> 活动倒计时<strong id="endtime"></strong>秒! </p> <input type="button" id="btn" value="立即购买" disabled="disabled" onClick="func()"/> </div> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> //倒计时30秒 var i = 30; function remainTime() { if (i > 0) { document.getElementById("endtime").innerHTML = i--; setTimeout("remainTime()", 1000); } if (i == 0) { $("p").text("活动开始"); $("p").css("background-color", "yellow"); //倒计时结束,按钮状态改为可用 document.getElementById("btn").disabled = false; } } remainTime(); //点击按钮触发的方法 function func() { alert("恭喜你抢到一个月饼"); } </script> </body> </html>
抢购代码
var button = document.getElementsByClassName("btn-biglarge"); //每秒执行一次,若按钮状态为可用,进行点击 setInterval(function() { if (button[0].disabled == false) { button[0].click(); } }, 1000);
打开控制台粘贴回车等待即可!