2013-04-11 56 views
0

我正在开发一个项目,我需要在一个页面上显示几个拍卖的状态。每个项目都有不同的结束日期。我使用cfquery从数据库中提取数据,然后使用cfoutput构建表。那部分很好。那里没有问题。我的问题是,如何将Keith Wood's countdown timer的多个实例放在表格中,以便每个项目都有倒计时?html表中的多个jquery倒计时

这是我的表

<table id="large" class="tablesorter" border="0" CELLSPACING="1" CELLPADDING="0" width="50%"> 
<thead> 
<tr class="tablesorter-headerRow"> 
    <th id="itemnum" class="sorter-numeric">ItemNum</th> 
    <th id="highbidder" class="sorter-numeric">HighBidder</th> 
    <th id="closenum" class="sorter-numeric">Time Left</th> 
    <th id="highbidprice" class="sorter-numeric">HighBid</th> 
</tr> 
</thead> 
<tbody> 
<cfoutput> 
<!--- Code builds the table body ---> 
<div class="countdown-styled clearfix" style="width:200px;"></div> 
</cfoutput> 
</tbody> 
</table> 

我已经看过这些头:1)Jquery multiple coundown 2)multiple countdowns on same page with jquery但这些要么似乎包括每个页面中的唯一行ID,然后在其他一些jQuery代码,或只是硬编码的ID。这个问题是我不知道最终版本上有多少物品。现在我有35但这不是恒定的,所以我不能这样做。任何想法或帮助吗?会真的很感激它。

+0

表体输出是什么样的?它的结构将直接影响你用来触发倒计时的jQuery。 – miah 2013-04-11 20:21:12

回答

0

下面是从他的网站的例子:

$(selector).countdown({until: new Date(2010, 12-1, 25)}); 

我假设你正在做的是这样的:

$('.countdown-styled').countdown({until: someDate}); 

这样的想法是,每个$('.countdown-styled')有不同的日期,你只需要找出如何指定每个不同元素的日期。

$('.countdown-styled').each(function (idx) { 
    var date = $(this).closest('tr').find('.date-label').text(); 

    $(this).countdown({ until: new Date(date) }); 
}); 

当然,我不知道从哪里得到之日起,因为我不能看到所有的代码,你可能需要调整,使得JavaScript日期对象从显示的代码,但那应该让你开始。