如何在jquery.counter触发多个实例的finish.countdown事件时重新加载页面?

时间:2015-09-21 05:32:00

标签: javascript jquery countdown jquery-countdown

我正在为jQuery countdown使用多个实例,并在计数器完成时实现页面重新加载 E.g。

$('.countdown').each(function() {
    var $this = $(this), 
    finalDate = $(this).data('countdown');

    $this.countdown((finalDate), function(event) {
        var days = event.strftime('%D');
        $(this).find('.days').children('span').html(days);
        $(this).find('.hours').children('span').html(event.strftime('%H'));
        $(this).find('.minutes').children('span').html(event.strftime('%M'));
        $(this).find('.seconds').children('span').html(event.strftime('%S'));
    });
    $(this).on('finish.countdown', function(event){
        /*if(!window.location.hash && !(window.location.hash.indexOf('_loaded') > -1)) {
            window.location = window.location + '#_loaded'; window.location.reload();
        }*/
        //If I put window location reload here it will goes into infinite loop. Also above commented code will reload page twice initially which is also not valid solution.
    });
});

问题:如果倒计时已经完成(例如00:00:00:00),那么第一次加载脚本时页面重新加载会发生两次,

我使用了localStorage概念但无法找到确切的解决方案。请帮忙

1 个答案:

答案 0 :(得分:0)

我几乎遇到了这个问题,页面不断重新加载。 尝试检查您的本地时间和服务器时间是否相同。在我的情况下,差异是两个小时,这是使页面不断循环的问题。 倒计时插件有一些关于时区感知的注释:http://hilios.github.io/jQuery.countdown/examples/timezone-aware.html