0
我試圖做一個頁面上的多倒計時,它看起來像:jQuery的多。每個倒計時()函數
<table>
<tr id="4236377487">
<td class="remain"></td>
<td>Something</td>
</tr>
<tr id="768769080">
<td class="remain"></td>
<td>Something else</td>
</tr>
</table>
倒計時必須放置在:
<td class="remain"><!-- countdown --></td>
每次倒計時都以行ID值開始。這裏是我的代碼,但它不工作:
$(document).ready(function(){
$('.remain').each(function() {
var count = $(this).attr("id");
countdown = setInterval(function(){
$(this).html(count + " seconds remaining!");
if (count == 0) {
//do something
}
count--;
}, 1000);
});
});
感謝您的幫助:)
法比安斯基
變種數= $(本).attr( 「ID」);正在查看.remain而不是父tr id。 – Jason 2011-03-19 07:38:26
我認爲你的整體設計不好。即使你使用parent獲取正確的id,你仍然會根據它的值進行更新,並且由於id始終爲常量,所以定時器實際上永遠不會減少。 – 2011-03-19 07:43:25