【问题标题】:Jquery multiple coundownjquery多个倒计时
【发布时间】:2011-08-06 16:06:13
【问题描述】:

我找到了这个脚本

$(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,我使用 &lt;?php echo $date ?&gt; 显示这个日期

我需要将 $date 传递给&lt;tr id=,以便显示到该日期的剩余时间,但保持相同的格式 Y-m-d H:i:s 甚至 H:i:s 会很棒。

我刚刚检查完http://keith-wood.name/countdown.html 的 jQuery Countdown 插件,但它不适合我,因为我需要多个倒计时。

我希望这很清楚,您可以理解我的问题。 提前感谢,对不起我的英语

【问题讨论】:

    标签: php jquery countdown


    【解决方案1】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2015-10-27
      • 2013-04-04
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多