js 如何指定时间刷新当前页面,下面有代码,高手帮我改下,谢谢
<script>functionGetRTime(){varEndTime=newDate('2016/09/2812:28:00');varNowTime=newDat...
<script>
function GetRTime(){
var EndTime= new Date('2016/09/28 12:28:00');
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=0;
var h=0;
var m=0;
var s=0;
var ss=0;
if(t>=0){
d=Math.floor(t/1000/60/60/24);
h=Math.floor(t/1000/60/60%24);
m=Math.floor(t/1000/60%60);
s=Math.floor(t/1000%60);
ss = Math.floor(t/100) % 10;
//hs=Math.floor(t/100%10);
}
function zfill(num, size) {
var s = "0" + num;
return s.substr(s.length-size);
}
document.getElementById("t_h0").innerHTML = "0"+h+":";
document.getElementById("t_m0").innerHTML = zfill(m,2) +":";
document.getElementById("t_s0").innerHTML = zfill(s,2) +":";
document.getElementById("t_hs0").innerHTML = "0"+ss + "";
}
setInterval(GetRTime,0);
if (t == 0) {
window.location.reload();
}
</script>
<span id="t_h0">00时</span> <span id="t_m0">00:</span> <span id="t_s0">00秒</span><span id="t_hs0">00毫秒</span></span>
当t的时间为0的时候,跳转本页面 展开
function GetRTime(){
var EndTime= new Date('2016/09/28 12:28:00');
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=0;
var h=0;
var m=0;
var s=0;
var ss=0;
if(t>=0){
d=Math.floor(t/1000/60/60/24);
h=Math.floor(t/1000/60/60%24);
m=Math.floor(t/1000/60%60);
s=Math.floor(t/1000%60);
ss = Math.floor(t/100) % 10;
//hs=Math.floor(t/100%10);
}
function zfill(num, size) {
var s = "0" + num;
return s.substr(s.length-size);
}
document.getElementById("t_h0").innerHTML = "0"+h+":";
document.getElementById("t_m0").innerHTML = zfill(m,2) +":";
document.getElementById("t_s0").innerHTML = zfill(s,2) +":";
document.getElementById("t_hs0").innerHTML = "0"+ss + "";
}
setInterval(GetRTime,0);
if (t == 0) {
window.location.reload();
}
</script>
<span id="t_h0">00时</span> <span id="t_m0">00:</span> <span id="t_s0">00秒</span><span id="t_hs0">00毫秒</span></span>
当t的时间为0的时候,跳转本页面 展开
1个回答
展开全部
稍微修改了下,代码如下:
<p id="init">网页初始化时间:</p>
<p id="time">倒计时:</p>
<script>
function GetRTime()
{
// 这里为了方便测试将结束时间定为了当前时间的十秒后,用时请自行修改
var endDate = new Date(endTime);
var curDate = new Date();
var t = endDate.getTime() - curDate.getTime();
if (t <= 0)
{
clearInterval(waitID);
window.location.reload();
return;
}
var innerDate = new Date(t);
var h = innerDate.getUTCHours();
var m = innerDate.getUTCMinutes();
var s = innerDate.getUTCSeconds();
var ms = innerDate.getUTCMilliseconds();
var ts = "倒计时:" + getFill(h) + ":" + getFill(m) + ":" + getFill(s) + "." + ms;
document.getElementById("time").innerHTML = ts;
}
function getFill(n)
{
return (n < 10 ? "0" : "") + n;
}
// 显示一个初始化时间,方便确定是否刷新
document.getElementById("init").innerHTML = "网页初始化时间:" + new Date().toLocaleString();
var endTime = new Date().getTime() + 10000;
var waitID = setInterval(GetRTime, 0);
</script>
更多追问追答
追问
到时间就刷新一次,现在是不停的刷新
追答
什么不停刷新,就是到指定时间刷新啊,这种低级错误怎么会犯呢,而且楼主也注意看下代码的逻辑啊,很好懂的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询