【问题标题】:Set jQuery.countdown Multiple instances on the same page with Timezone Aware (MomentJS)使用时区感知(MomentJS)在同一页面上设置 jQuery.countdown 多个实例
【发布时间】:2018-05-30 04:45:17
【问题描述】:

我需要根据网站上的文档使用 MomentJS 在同一页面上设置 jQuery.countdown 多个实例:

到目前为止,我有这个:

<div data-countdown="2018-01-01 12:00:00"></div>
<div data-countdown="2019-01-01 12:00:00"></div>
<div data-countdown="2020-01-01 12:00:00"></div>

<script>
jQuery( document ).ready(function() {

    jQuery("[data-countdown]").each(function() {

        var jQuerythis = jQuery(this), finalDate = jQuery(this).data("countdown");

        finalDate = moment.tz(finalDate, "Europe/London"); // <-- ***THIS IS NOT WORKING***

        jQuerythis.countdown(finalDate, function(event) {           
            jQuerythis.html(event.strftime("%D days %H:%M:%S"));            
        });

    });

});             
</script>

但它不起作用。我不认为下面这句话总体上是正确的:

finalDate = moment.tz(finalDate, "Europe/London");

MomentJS 安装正确,如果我删除上面的一行,一切正常,但没有时区意识。

您能提供一些建议吗?

【问题讨论】:

  • finalDate 是什么格式?
  • 格式:Y-m-d H:i:s 。我更新了问题中的代码。它可以工作,但我试图让它知道时区。

标签: javascript jquery html jquery-countdown


【解决方案1】:

对于需要它的人,我在以下行中遗漏了这部分“.toDate()”:

jQuerythis.countdown(finalDate.toDate(), function(event) {

所以现在一切都很顺利!

我在这篇博客文章Final Countdown jQuery plugin Multiple instances on the same page with Timezone Aware的帮助下找到了解决方案

jQuery.countdown 具有时区感知 (MomentJS) 的同一页面上的多个实例。

感谢所有帮助过的人!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-02
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多