<html>
<head>
<title>控制页面刷新时间</title>
<script language="javascript">
var i=0;
var flag=null;
function time(){ //显示时间跳动
var timeShow=document.getElementById("timeShow");
timeShow.innerText=i;
i--;
flag=setTimeout("time()",1000);
}
function changeTime() {
var nowTime=document.getElementById("newTime").value;//得到输入的刷新时间
if(nowTime=="") {alert("请输入新的刷新时间");return;}
setTimeRef(nowTime); //显示当前刷新时间
clearTimeout(flag);i=nowTime;time();//清除原来定时器,从头开始计时
setTimeout("window.location.reload()",parseInt(nowTime)*1000); //定时刷新
}
function setTimeRef(nowTime){
document.getElementById("timeRef").innerText=nowTime;
}
</script>
</head>
<body onLoad="">
<p>当前刷新时间为: <span id="timeRef" style="color:red"></span>秒</p>
<p>刷新倒计时: <span id="timeShow" style="color:red"></span>秒</p>
<p>输入新的刷新时间: <input id="newTime" type="text" size="4"> <input type="button" value="提交" onClick="changeTime()"> </p>
</body>
</html>