javascript - 当倒计时达到 0 时使用 Javascript 重新加载页面

标签 javascript

我正在使用下面的函数来显示倒计时,并希望在计数器达到 0 时重新加载页面。 我只是坐着看着计数器降到 0,什么也没发生。 location.reload() 不是应该刷新页面吗?

function secondPassed() {
    var numDays = Math.floor(seconds / 86400);
    var numHours = Math.floor((seconds % 86400) / 3600);
    var numMinutes = Math.floor(((seconds % 86400) % 3600) / 60);
    var numSeconds = ((seconds % 86400) % 3600) % 60;

    if (numSeconds < 10) {
        numSeconds = "0" + numSeconds; 
    }

    document.getElementById('count').innerHTML = "<span class='fa fa-clock-o' aria-hidden='true'></span> " 
            + ('' + numDays).slice(-2) + "d " + "" 
            + ('' + numHours).slice(-2) + "h " + "" 
            + ('' + numMinutes).slice(-2) + "m " + "" 
            + ('' + numSeconds).slice(-2) + "s ";

    if (seconds <= 0) {
        clearInterval(countdownTimer);
        location.reload();
    } else {
        seconds--;
    }
}

setInterval(function () {
    secondPassed();
}, 1000);

最佳答案

尝试这样

/*
    if true page will always reload from server
    else page will load from cache
*/
window.location.reload(true);

关于javascript - 当倒计时达到 0 时使用 Javascript 重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30926070/

相关文章:

javascript - Reactjs:使用 Reactjs 的 jQuery 自定义内容滚动器

javascript - 为什么替换功能不能正常使用?

javascript - 语法错误 : Unexpected token function - Async Await Nodejs

javascript - 使用 getJson 分解树

javascript - 显示文本区域中重复的单词数

javascript - jQuery submit()、change() 和页面刷新

javascript - 范围变量 ng-bind-html 未及时加载

javascript - 停止加载单击的链接,并让周围的元素使用 Angularjs ng-click 处理该操作

javascript - 如何使用 AngularJS 获取光标下的单词?

javascript - jQuery AJAX GET 请求调用不正确