抱歉再次打扰,我还有另一个关于 javascript 的问题
这是 mysql 数据库表中时间计数器的代码:
<script type='text/javascript'>
function cronometru(timp_ramas) {
Ore = Math.floor(timp_ramas / 3600);
minute = Math.floor((timp_ramas - Ore * 3600) / 60);
secunde = timp_ramas - minute * 60 - Ore * 3600;
if (Ore < 10){ Ore = "0"+ Ore; }
if (minute < 10){ minute = "0" + minute; }
if (secunde < 10){ secunde = "0" + secunde; }
if (timp_ramas > 0) {
timp_ramas--;
document.getElementById("timp").innerHTML = Ore + ':' + minute + ':' + secunde;
//document.getElementById("cumpara").innerHTML ="<br><a href='piata.php?cumpara=<?php echo $id_functie; ?>'>Cumpara</a>";
setTimeout("cronometru("+timp_ramas+")", 1000);
} else {
document.getElementById("timp").innerHTML = "[Licitatia s-a terminat]";
// document.getElementById("cumpara").innerHTML = "[Nu mai poti cumpara]";
}
}
</script>
然后在php中,我在while函数中将此脚本调用为表格形式
while($informatie = mysql_fetch_array($sql))
{
$timp_ramas = $informatie['data_limita'] - time();
//........................................
echo " <td width='40%' align='justify'>
Pret : ".$informatie['obiect_pret']."
<br />
Timp ramas : <span id='timp'> ";
echo " <script type='text/javascript'> cronometru(".$timp_ramas.") </script></span> ";
if ($informatie['obiect_cantitate'] > 1)
echo "<br>Cantitate disponibila: ".$informatie['obiect_cantitate']." ";
if ($informatie['data_limita'] > 1)
echo "<br><a href='piata.php?cumpara=".$informatie['id']."'>Cumpara</a>";
echo "</td>";
}
我不明白为什么如果我有 3 行,每行都有来自数据库的不同信息,那么只有首先访问 javascript。其他行完美无缺,它们从数据库中检索所有信息,但这并不希望显示每一行的计时器(倒计时)。为什么?