如何重载页面时使用jquery.计数器触发完成.多个实例的倒计时事件

How to reload page when jquery.counter trigger finish.countdown event for multiple instance?

本文关键字:事件 倒计时 实例 计数器 jquery 重载 何重载      更新时间:2023-09-26

我使用多个实例的jQuery倒计时和实现页面重载时计数器完成例如

$('.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概念,但无法找到确切的解决方案。请帮忙

我几乎有这个问题的页面不断重新加载瞬间。尝试检查您的本地时间和服务器时间是否相同。在我的例子中,这个差异是两个小时,这就是让页面进入恒定循环的问题。倒计时插件有一些关于时区意识的注意事项:http://hilios.github.io/jQuery.countdown/examples/timezone-aware.html