2011-08-06 3 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에이 코드 :

4236375205 seconds remaining! Something 
768766798 seconds remaining! Something else 

나는 날짜를 가지고 :

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

결과이 같은 것입니다 다음 형식을 사용합니다. 2011-10-29 10:05:00,이 날짜는 <?php echo $date ?>

$ date를 <tr id=으로 전달하면 그 날짜까지 남은 시간이 표시되지만 같은 형식 인 Y-m-d H : i : s 또는 H : i : s를 유지하는 것이 좋습니다.

jQuery 카운트 다운 플러그인을 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); 
    }); 
}); 
시도
관련 문제