【问题标题】:Jquery refresh page after countdown hits 0倒计时达到0后Jquery刷新页面
【发布时间】:2014-12-29 12:13:51
【问题描述】:

我正在使用 Keith Wood Jquery 倒数计时器 (http://keith-wood.name/countdown.html),我想这样做,以便当计时器达到 0 时页面会刷新。不幸的是,我无法做到这一点。这是我的代码:

$(function () {
        var now = new Date($.now());
        var austDay = new Date();
        austDay = new Date(//php stuff to get the date from the database..);
        $('#defaultCountdown').countdown({until: austDay, format: 'DHMS'});
        if (austDay <= now) {
            location.reload();
        }
});

提前致谢。

【问题讨论】:

    标签: javascript jquery refresh countdown


    【解决方案1】:

    根据链接到的文档,您可以指定一个onExpiry 回调,用于当倒计时归零时。然后你提供一个函数,可以在那个时候做任何你喜欢的事情:

    $('#defaultCountdown').countdown({
        until: austDay,
        format: 'DHMS',
        onExpiry: function() { location.reload(); }
    });
    

    (上面的代码我没有测试过,但是在the doco中似乎很清楚。)

    【讨论】:

    • 是的,有效。非常感谢,下次我应该阅读更多。 :P
    【解决方案2】:

    来自documentation

    onExpiry:倒计时时调用的回调函数 达到零。在函数中 this 指的是除法 持有小部件。没有传入任何参数。使用 expiryText 或 到期时基本功能的 expiryUrl 设置。

    $(selector).countdown({
        until: liftoffTime, onExpiry: liftOff});
    
    function liftOff() {
        alert('We have lift off!');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      相关资源
      最近更新 更多