关于秒杀倒计时按钮的方法

 function Load() {
    var stringTime = "2020-06-24 11:20: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 = "2020-06-24 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--;
        }
    }
    Load();

猜你喜欢

转载自www.cnblogs.com/sange118/p/13196027.html