我正在努力使它当stime函数达到00:00时,div id“refresh”将刷新内部的内容..
<script type="text/javascript">
var currenttime = '<? print date("F d, Y H:i:s", time())?>'
var montharray=new
var serverdate=new Date(currenttime)
function stime(){
var fiveMinutes = 5 * 60 * 1000;
var untilNext = fiveMinutes - (serverdate % fiveMinutes);
var timer=(untilNext / 1000)
var minutes= "0" + Math.floor(untilNext / 1000 / 60)
var seconds= "0" + (timer - minutes * 60)
document.getElementById("stime").innerHTML=minutes.substr(-2)+":"+seconds.substr (-2)
}
window.onload=function(){
setInterval("stime()", 1000)
}
</script>
<?php
echo '<div id="refresh">Health: <span style="float:right" id="stime"></span></div><br />';
?>
是否可以使用该函数,在stime函数达到00:00时创建另一个刷新div的函数?
答案 0 :(得分:0)
像这样制作你的setInterval:
window.onload=function(){
setInterval(stime, 1000)
}
答案 1 :(得分:0)
<script type="text/javascript">
var currenttime = '<? print date("F d, Y H:i:s", time())?>';
var montharray=new Array();
var serverdate=new Date(currenttime);
function doRefresh(){
//code to refresh or ajax.
}
function stime(){
var fiveMinutes = 5 * 60 * 1000;
var untilNext = fiveMinutes - (serverdate % fiveMinutes);
var timer=(untilNext / 1000);
var minutes= "0" + Math.floor(untilNext / 1000 / 60);
var seconds= "0" + (timer - minutes * 60);
var timeString = minutes.substr(-2)+":"+seconds.substr(-2);
document.getElementById("stime").innerHTML=timeString;
if(timeString==="00:00")
{
doRefresh();
}
}
window.onload=function(){
setInterval("stime()", 1000);
}
</script>
<?php
echo '<div id="refresh">Health: <span style="float:right" id="stime"></span></div><br />';
?>
尝试使用&#34;;&#34;结束语句。
使用缩进会很好。(增加可读性)。请不要挂变量。
var montharray=new