开发者

jquery multiple keith-wood countdown plugin on one page

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开发者_C百科 sale data? I mean, how can I make it multiple and working?


You need to uniquely identify each element. If there is a sale id i'd do it like this:

$('#defaultCountdown<?php echo $sale->Id?>').countdown(...);
...
<div id="defaultCountdown<?php echo $sale->Id?>"></div>

Or just use a counter:

<?  
    $count = 0;
    foreach ($sales as $sale):
    $count++; 
?>

$('#defaultCountdown<?php echo $count ?>').countdown(...);
...
<div id="defaultCountdown<?php echo $count ?>"></div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜