0
我一直在努力让我的头在这一段时间现在。卡住创建一个php/javascript倒数计时器
我正在尝试创建一个倒数计时器。最终,我希望它从早上8点开始每5小时重置一次。但是现在我无法弄清楚是否正确设置了小时,分钟和秒数来正确倒数。
这是我到目前为止的代码:
<?php
$timeTo = strtotime('08:00:00').'<br />';
$timeNow = strtotime('now').'<br />';
$differenceInSeconds = $timeTo - $timeNow;
?>
<script type="text/javascript">
var s= "<?php Print($differenceInSeconds);?>";
var h= Math.floor(s/3600);
s-= h*3600;
var m= Math.floor(s/60);
s -= m*60;
var counter=setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
s=s-1;
if(h >= 0 && m >= 0 && s <= -1){
m=m-1;
s=59;
if(h>= 0 && m < 0 && s <= -1){
h=h-1;
m=59;
s=59;
if (s <= -1)
{
//counter ended, reset counter
return;
}
}
}
//Do code for showing the number of seconds here
document.getElementById("timer").innerHTML=(h <= 0 ? ' ' : h+"hr ")+(m <= 0 ? ' ' : m+"min ")+(s < 10 ? '0'+s : s+"secs "); // watch for spelling
}
</script>
我在这里找错了树?我对时代和JavaScript很陌生,所以觉得很难。
虽然回答'我不会回答'可能是不正确的,仍然+1为调用自我教育 –