秒杀的倒计时按钮实现

ps:只有按钮 没有秒杀 还在做
一个小小的按钮 花了我一个下午的时间  自己水平还是太次啊
直接贴代码html>
html lang="en">
head>
    meta charset="UTF-8">
    </title>
    script>
head>
body>

br>

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 20:02: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>
http://www.cnblogs.com/zyjfire/articles/6775383.html  食用

原文地址:https://www.cnblogs.com/ghjbk/p/6781655.html