我有一个 JS 函数,我试图从 PHP 代码中调用它。我调用这个 JS 函数循环运行的次数(例如 5)。代码:
<script>
//var seconds = '';
function csst(rowid){ alert(rowid);
window.setInterval(function(){
secondPassed();
function secondPassed() {
seconds = parseInt($("#ts").val());
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
$("#countdown1"+rowid).html(minutes + ":" + remainingSeconds);
if (seconds <= 0) {
clearInterval();
document.getElementById('countdown1'+rowid).innerHTML = "Buzz Buzz...";
} else {
seconds--;
$("#ts").val(seconds);
}
}
},1000);
}
</script>
<?php
$c = 1;
echo '<input type="hidden" value="50" id="ts" name="ts"/>';
echo "<table border='1'>";
while ($c <=5)
{
echo '<script>
csst('.$c.');
</script>';
echo '<tr><td>row'.$c.'</td><td><p id="countdown1'.$c.'"></td></tr>';
$c++;
}
echo "</table>";
?>
我需要在表格的每一行中同时显示一个时间递减计数器。使用相同的 JS 函数。
任何帮助,请!
达令说