开发者

Jquery multi-countdown .each() function

I'm trying to make a multi-countdown on a page, which looks like :

<table>  
  <tr id="4236377487">
    <td class="remain"></td>
    <td>Something</td>
  </tr>
  <tr id="768769080">
    <td class="remain"></开发者_Python百科td>
    <td>Something else</td>
  </tr>
</table>

Countdown must be placed in :

<td class="remain"><!-- countdown --></td>

Each countdown starts with the row id value. Here's my code, but it doesn't work :

$(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);
  });  
});

Thank for your help :)

Fabien


$(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);
  });  
});

Try it here : http://jsfiddle.net/moeishaa/PwG45/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜