基斯伍德倒计时总是显示0

时间:2016-05-03 15:09:21

标签: javascript jquery jquery-countdown

我正在尝试使用此代码在网页上实施Keith Wood Countdown,放在最终正文标记之前:

$(function(){                                                   
        var untilDate = new Date(2016,4,4,8,0);
        console.log(untilDate.getFullYear() + "-" + untilDate.getMonth() + "-" + untilDate.getDate());
        $("#next-departure").countdown($.countdown.regionalOptions["fr"]); 
        $("#next-departure").countdown(
            {
                until:untilDate,
                format:'yowdHMS'
            }
        );
    });

控制台中没有错误且日期正确但是......始终显示: No countdown running enter image description here

对我缺少的东西有任何想法吗?

1 个答案:

答案 0 :(得分:0)

倒计时显示0,因为它是使用空参数创建的,代码为:

 $("#next-departure").countdown($.countdown.regionalOptions["fr"]); 

以下代码行(您指定了正确的参数)不会重新创建倒计时。

我的解决方案是在jquery.countdown-fr.js文件后面包含区域设置的文件jquery.countdown.js

<script type="text/javascript" src="jquery.countdown-fr.js"></script>

您可以在此处找到此文件:https://github.com/kbwood/countdown/blob/master/jquery.countdown-fr.js

然后,使用以下代码创建倒计时:

$(function(){
    var untilDate = new Date(2016,4,4,8,0); 
    $("#next-departure").countdown({
        until:untilDate,
        format:'YOWDHMS'
    });
});

在这里小提琴:https://jsfiddle.net/cu246mh2/

相关问题