gpt4 book ai didi

php - Jquery多重倒计时

转载 作者:行者123 更新时间:2023-12-01 06:05:23 24 4
gpt4 key购买 nike

我找到了这个脚本

$(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 ?> 显示此日期

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

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

我希望这很清楚,您可以理解我的问题。预先感谢并抱歉我的英语

最佳答案

试试这个

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

关于php - Jquery多重倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6968041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com