多个拍卖项目的javascript计时器不适用于php
我正在尝试为在线拍卖项目实现一个倒计时,但它只对显示的一个项目有效。代码如下:多个拍卖项目的javascript计时器不适用于php,javascript,php,mysql,Javascript,Php,Mysql,我正在尝试为在线拍卖项目实现一个倒计时,但它只对显示的一个项目有效。代码如下: <?php $result=mysql_query("select * from `date`")or die(mysql_error()); while($row=mysql_fetch_array($result)) { $then = $row['date']; $now = time(); $thenTimestamp = strtotime($then) + strtotime($now); $
<?php
$result=mysql_query("select * from `date`")or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$then = $row['date'];
$now = time();
$thenTimestamp = strtotime($then) + strtotime($now);
$difference = $thenTimestamp - $now;
echo '<script type="text/javascript">
var seconds ='.$difference.';
function secondPassed() {
var hours=Math.round(seconds / 3600);
var minutes = Math.round(((seconds - 30)/60)%60);
var remainingSeconds = seconds % 60;
document.getElementById("countdown").innerHTML = hours+ ":"+ minutes + ":" + remainingSeconds;
if (seconds == 0) {
// clearInterval(countdownTimer);
document.getElementById("countdown").innerHTML = "Buzz Buzz";
} else {
seconds--;
}
}
setInterval("secondPassed()", 1000);
</script>
<body>
<span id="countdown"></span>
</body>';
}
?>
我必须在明天之前提交我的在线拍卖项目。所以,我需要解决方案。请帮帮我。
提前谢谢 你的问题/问题?以上脚本作品非常适合一次拍卖。如果我放置了多个拍卖,它只显示最后添加的拍卖的计时器。不是所有的吗?简单地说,你必须将每个拍卖放在单独的HTML元素中,并将你的代码封装在一个函数中,该函数使用该元素id或类名来运行计数器。你能给出一个演示吗?我试过上面的代码,但它只适用于一次拍卖。