我需要根据网站上的文档使用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安装正确,如果我删除上面的一行,一切正常但没有时区感知。
你能提供一些建议吗?
对于任何需要它的人,我在以下行中错过了这部分“.toDate()
”:
jQuerythis.countdown(finalDate.toDate(), function(event) {
所以现在一切都很美妙!
我在这篇博客文章Final Countdown jQuery plugin Multiple instances on the same page with Timezone Aware的帮助下找到了解决方案
jQuery.countdown使用Timezone Aware(MomentJS)在同一页面上的多个实例。
感谢所有帮助过的人!