懒得解释了 直接贴代码<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>index</title> <script src="__PUBLIC__/jquery-2.1.1.min.js"></script></head><body><input type="button" id="btn" value="秒杀" disabled="true"/></body><script type="text/javascript">$(function(){ var stringTime = "2017-04-27 19:44:00"; var timestamp2 = Date.parse(new Date(stringTime)); timestamp2 = timestamp2 / 1000; //获取到的 格式日期 的时间戳 var myDate = new Date(); var timestamp = myDate.getTime()/1000; //当前时间戳 获取的时间戳为毫秒 需除1000 timestamp = timestamp.toFixed();
//过了某时间 直接不可点var stringTime3 = "2017-04-27 21:00:00";var timestamp4 = Date.parse(new Date(stringTime3));timestamp4 = timestamp4 / 1000; //获取到的 格式日期 的时间戳if(timestamp>timestamp4){ alert('活动已结束'); return;}
if(timestamp>timestamp2 && timestamp<timestamp4){ $("#btn").val("秒杀").removeAttr("disabled"); return;}
var count = timestamp2 - timestamp;var countdown = setInterval(CountDown, 1000);function CountDown() { $("#btn").val("离活动开始还有" + count + "秒"); if (count == 0) { $("#btn").val("秒杀").removeAttr("disabled"); clearInterval(countdown); } count--;}
});</script></html>可搭配 http://www.cnblogs.com/zyjfire/articles/6775383.html 食用
来源:https://www.cnblogs.com/zyjfire/p/6776199.html