2013-04-11 60 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日期對象從顯示的代碼,但那應該讓你開始。