我需要根据网站中的文档,使用 MomentJS 在具有 Timezone Aware 的同一页面上设置 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 已正确安装,如果我删除上面的一行,一切正常,但没有时区意识。
您能提供一些建议吗?
最佳答案
对于需要它的人,我在以下行中遗漏了这部分“.toDate()
”:
jQuerythis.countdown(finalDate.toDate(), function(event) {
现在一切都很顺利!
我在这篇博客文章 Final Countdown jQuery plugin Multiple instances on the same page with Timezone Aware 的帮助下找到了解决方案
jQuery.countdown 具有时区感知 (MomentJS) 的同一页面上的多个实例。
感谢所有提供帮助的人!
关于javascript - 使用 Timezone Aware (MomentJS) 在同一页面上设置 jQuery.countdown 多个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47841394/