jquery 一页上有多个 keith-wood 倒计时插件
我正在使用 jQuery Keith-Wood 插件在我的页面上显示一个倒计时器,并且效果很好。
现在我想显示多个倒计时,但它似乎不起作用(它仅适用于第一个元素)。
这就是我所做的:
<? foreach ($sales as $sale): ?>
<script>
$(function () {
var austDay = new Date();
austDay = new Date(<?php echo date('Y', strtotime($sale->end))?>,<?php echo (date('m', strtotime($sale->end))-1)?>,<?php echo date('d-1', strtotime($sale->end))?>,<?php echo date('h', strtotime($sale->end))?>,<?php echo date('i', strtotime($sale->end))?>,<?php echo date('s', strtotime($sale->end))?>);
$('#defaultCountdown').countdown({until: austDay, format: 'dHMS'});
});
</script>
<div id="defaultCountdown"></div>
知道如何让它适用于每个销售数据吗?我的意思是,我怎样才能让它变得多重并且有效?
I am using the jQuery Keith-Wood plugin for showing one countdown timer on my page, and it works fine.
Now I want to display multiple countdowns, but it doesn't seem to work (it works only for the first element).
Here is what i do:
<? foreach ($sales as $sale): ?>
<script>
$(function () {
var austDay = new Date();
austDay = new Date(<?php echo date('Y', strtotime($sale->end))?>,<?php echo (date('m', strtotime($sale->end))-1)?>,<?php echo date('d-1', strtotime($sale->end))?>,<?php echo date('h', strtotime($sale->end))?>,<?php echo date('i', strtotime($sale->end))?>,<?php echo date('s', strtotime($sale->end))?>);
$('#defaultCountdown').countdown({until: austDay, format: 'dHMS'});
});
</script>
<div id="defaultCountdown"></div>
Any idea about how could I could make it work for each sale data? I mean, how can I make it multiple and working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要唯一地标识每个元素。如果有销售 ID,我会这样做:
或者只使用计数器:
You need to uniquely identify each element. If there is a sale id i'd do it like this:
Or just use a counter: