首页 > 解决方案 > 如何使用 Cookie 防止刷新倒数计时器以及如何在计时器到达 0 时显示消息

问题描述

如何使用 Cookie 防止刷新倒数计时器以及如何在计时器到达 0 时显示消息

var secondsBeforeExpire = 5;

// This will trigger your timer to begin
var timer = setInterval(function(){
    // If the timer has expired, disable your button and stop the timer
    if(secondsBeforeExpire <= 0){
        clearInterval(timer);
        $("#buynowofferone").prop('disabled',true)
        document.getElementById("nextoffer").innerHTML = " SHOW ME NEXT OFFER"
        $("#time-remaining").hide()
        document.getElementById("smile").innerHTML = "OFFER EXPIRED ☹";
    }
    // Otherwise the timer should tick and display the results
    else{
        // Decrement your time remaining
        secondsBeforeExpire--;
        $("#time-remaining").text( " Expires in " + secondsBeforeExpire + " Seconds ⚠") ;

    }
},1000);

标签: javascripthtml

解决方案


推荐阅读