gpt4 book ai didi

php - 使用单元格值作为参数将 javascript 函数应用于表格的每一行?

转载 作者:行者123 更新时间:2023-11-28 02:21:23 26 4
gpt4 key购买 nike

我有一个表(从 php 数组生成),显示用户当前的拍卖。该表的其中一列显示拍卖的剩余时间。我正在使用 jquery 倒计时插件 ( http://www.keith-wood.name/countdown.html ),它使剩余时间倒计时为零。

如何使用不同的剩余时间将倒计时功能应用于每一行?

$(function () {
$('#countdown').countdown({until: +remainingTime, format: 'HMS', compact: true});
});

我正在尝试,但似乎不起作用:

 foreach($tradePile['auctionInfo'] as $auction)
{
if ($auction['tradeState'] == "active")
{
$i++;
echo '<tr>';
echo '<td><a href="player.php?id='.$auction['itemData']['resourceId']. '">'.$stats['first_name'].' '.$stats['last_name'].'</a></td>';
echo'<td>'.$auction['itemData']['rating'].'</td>';
echo'<td>'.$buyNowPrice.'</td>';
echo'<td>'.$auction['startingBid'].'</td>';
//remaining time for each auction:
//$auction['expires']
?>
<td>
<script>$(function () {$('#countdown<?php echo $i; ?>').countdown({until: +<?php echo $auction['expires'] ?>, format: 'HMS', compact: true});});</script>
<div id="countdown<?php echo $i; ?>"></div>
</td>
<?php
echo'</tr>';
}
}

最佳答案

使用each循环遍历所有表行。不要用 PHP 编写 JS 脚本。

创建像这样的表结构,使用增量 i 变量定义 id:

<table id="myTable">
<tr id="1" expire="55">
<td id="countdown-1">....</td>
...
</tr>
</table>

还有这样的 JS 代码:

$(function () {
$('#myTable tr').each(function(){
var remainingTime = $(this).attr('expire');
var id = $(this).attr('id');
$('#countdown-'+id).countdown({until: +remainingTime, format: 'HMS', compact: true});
});
});

关于php - 使用单元格值作为参数将 javascript 函数应用于表格的每一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15608930/

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