2011-08-06 6 views
2

私はjQueryの複数coundown

$(document).ready(function(){ 
    $('tr[id]').each(function() { 
    var $this = $(this); 
    var count = parseInt($this.attr("id")); 
    countdown = setInterval(function(){ 
     $('.remain', $this).html(count + " seconds remaining!"); 
     if (count-- == 0) { 
      //do something 
      clearInterval(countdown); 
     } 
    }, 1000); 
    }); 
}); 

とHTML上でこのスクリプトを見つけ、このコード:

<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> 

結果はこのようなものです:

4236375205 seconds remaining! Something 
768766798 seconds remaining! Something else 

私は日付を持っています次の形式2011-10-29 10:05:00、私はこの日付を<?php echo $date ?>

$日付を<tr id=に渡すと、その日付までに残った時間が表示されますが、同じ形式のY-m-d H:i:sまたはH:i:sを保持することができます。

jQuery Countdownのプラグインをhttp://keith-wood.name/countdown.htmlにチェックするだけで済みますが、複数のカウントダウンが必要なので、私には合いません。

私はこれが明確で、あなたが私の質問を理解できることを願っています。 事前に感謝し、私の英語

答えて

0

のため申し訳ありませんが

$(document).ready(function(){ 
    $('tr[id]').each(function() { 
    var $this = $(this); 
    var count = parseInt($this.attr("id")); 
    countdown = setInterval(function(){ 
     var curDate = (new Date()).getMilliseconds(); 
     var newDate = new Date(count-curDate); 
     var dateString = newDate.getHours() + ":" + newDate.getMinutes() + ":" + newDate.getSeconds(); 
     $('.remain', $this).html(dateString + " seconds remaining!"); 
     if (count-- == 0) { 
      //do something 
      clearInterval(countdown); 
     } 
    }, 1000); 
    }); 
}); 
これを試してみてください