页面为活动页时定时刷新 如题,用js改怎么去实现, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <head> <meta http-equiv="refresh" content="600/*(刷新间隔:秒)*/"></head> <script>function doit(){ location.reload();}var tid;window.onfocus=function(){ tid = setTimeout("doit()", 3000);}window.onblur=function(){ clearTimeout(tid)}window.onload=function(){ document.body.disabled = true; tid = setTimeout("doit()", 3000);}</script> 每隔5秒更新刷本页<meta http-equiv="refresh" content="5">1分钟后跳转至其他页面<meta http-equiv="Refresh" content="60;URL=/要刷新的页面"> 脚本刷新 <script language="javascript"> setTimeout("window.location.reload(true)",5000); </script> setTimeout("window.location.reload(true)",5000); 这句我在页面中早就用过了,主要是不知道用js判断当前页面是否为活动页面.如果能判断就什么功能都能实现了 JS 定时器 (setInterval 和 setTimeout 函数)DEMO1:<html><head><script language="JavaScript"><!--function Refresh(){ var newDateObj = new Date(); document.form1.txt_Time.value=newDateObj.toLocaleString();//使用当前区域设置并已被转换为字符串}var MyInterval=setInterval("Refresh()",1000);function Stop(){ if(event.srcElement.value=="STOP") //if(document.form1.btn_Stop.value=="STOP") { clearInterval(MyInterval); document.form1.btn_Stop.value="START"; } else if(event.srcElement.value=="START") //else if(document.form1.btn_Stop.value=="START") { MyInterval=setInterval("Refresh()",1000); document.form1.btn_Stop.value="STOP"; }}function Clear(){ if(event.keyCode==8)//退格键 { event.srcElement.value=""; }}//--></script></head><body><form name="form1">当前时间:<input type=text name="txt_Time" size=30 onkeydown="Clear()"><input type="button" name="btn_Stop" value="STOP" onClick="Stop()"></form></body></html>DEMO2:<SCRIPT>function Refresh(){ Time.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay()); setTimeout("Refresh()",1000);}var timer=setTimeout("Refresh()",1000);function Stop(){ if(event.srcElement.value=="STOP") { clearTimeout(timer); document.all.btn_Stop.value="START"; } else if(event.srcElement.value=="START") { timer=setTimeout("Refresh()",1000); document.all.btn_Stop.value="STOP"; }}</SCRIPT><body><DIV style="background-color:#eeeeee" id="Time"></DIV><input type="button" name="btn_Stop" value="STOP" onClick="Stop()"><button name='btnTest' onclick="javascript:alert(this.name)">测试</button></body> L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> </head> <body> <div id="divOutput"></div> <script type="text/javascript"> <!--var div = document.getElementById("divOutput");window.onblur = function() { div.innerHTML = "Blur " + new Date() + "<br />" + div.innerHTML;};window.onfocus = function() { div.innerHTML = "Focus " + new Date() + "<br />" + div.innerHTML;}; //--> </script> </body></html> 补充一句,window.onfocus 时启动定时器,window.onblur 时终止定时器!Web 开发常用手册JScript语言参考.rarhttp://download.csdn.net/source/308916DHTML参考手册.rarhttp://download.csdn.net/source/308913样式表中文手册.chmhttp://download.csdn.net/source/304124 setTimeout("doit()", 3000); 在IE里好像还有BUG,就是有时点击内容.也会运行一次 调试一下,上面的那些例子在FF3.5通过,但在IE7有问题.比如页面只有一两行内容.这样点击一下.页面没内容的空白部分.也当是失去焦点了. 这个是IE的document的高度问题,利用js把body设高一点,跟浏览器一样高 【extjs】自定义事件如何在处理函数里引用event对象? 请问,鼠标经过图片显示图片原图大小怎么实现? 有无emeditor的js代码自动格式化插件? 求助jquery 的淡入效果实现不了 JQuery获取父容器 script的src属性 【初学者】大家帮我看看这是什么原因 正则表达式,不匹配括号里面的字符 高分求javascript如何进行部门树的遍历 js控制checkbox重置 跪求--多标签浏览器关闭问题 解密js文件
<meta http-equiv="refresh" content="600/*(刷新间隔:秒)*/">
</head>
<script>
function doit(){
location.reload();
}
var tid;window.onfocus=function(){
tid = setTimeout("doit()", 3000);
}
window.onblur=function(){
clearTimeout(tid)
}window.onload=function(){
document.body.disabled = true;
tid = setTimeout("doit()", 3000);
}
</script>
<meta http-equiv="refresh" content="5">1分钟后跳转至其他页面
<meta http-equiv="Refresh" content="60;URL=/要刷新的页面"> 脚本刷新
<script language="javascript">
setTimeout("window.location.reload(true)",5000);
</script>
这句我在页面中早就用过了,主要是不知道用js判断当前页面是否为活动页面.
如果能判断就什么功能都能实现了
DEMO1:
<html><head><script language="JavaScript">
<!--function Refresh()
{
var newDateObj = new Date();
document.form1.txt_Time.value=newDateObj.toLocaleString();//使用当前区域设置并已被转换为字符串
}var MyInterval=setInterval("Refresh()",1000);function Stop()
{
if(event.srcElement.value=="STOP")
//if(document.form1.btn_Stop.value=="STOP")
{
clearInterval(MyInterval);
document.form1.btn_Stop.value="START";
}
else if(event.srcElement.value=="START")
//else if(document.form1.btn_Stop.value=="START")
{
MyInterval=setInterval("Refresh()",1000);
document.form1.btn_Stop.value="STOP";
}
}function Clear()
{
if(event.keyCode==8)//退格键
{
event.srcElement.value="";
}
}
//-->
</script>
</head>
<body><form name="form1">
当前时间:<input type=text name="txt_Time" size=30 onkeydown="Clear()">
<input type="button" name="btn_Stop" value="STOP" onClick="Stop()">
</form></body></html>
DEMO2:
<SCRIPT>function Refresh()
{
Time.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());
setTimeout("Refresh()",1000);
}var timer=setTimeout("Refresh()",1000);function Stop()
{
if(event.srcElement.value=="STOP")
{
clearTimeout(timer);
document.all.btn_Stop.value="START";
}
else if(event.srcElement.value=="START")
{
timer=setTimeout("Refresh()",1000);
document.all.btn_Stop.value="STOP";
}
}</SCRIPT><body>
<DIV style="background-color:#eeeeee" id="Time"></DIV>
<input type="button" name="btn_Stop" value="STOP" onClick="Stop()"><button name='btnTest' onclick="javascript:alert(this.name)">测试</button>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<div id="divOutput"></div>
<script type="text/javascript">
<!--
var div = document.getElementById("divOutput");window.onblur = function() {
div.innerHTML = "Blur " + new Date() + "<br />" + div.innerHTML;
};window.onfocus = function() {
div.innerHTML = "Focus " + new Date() + "<br />" + div.innerHTML;
}; //-->
</script>
</body>
</html>
http://download.csdn.net/source/308916DHTML参考手册.rar
http://download.csdn.net/source/308913样式表中文手册.chm
http://download.csdn.net/source/304124
比如页面只有一两行内容.这样点击一下.页面没内容的空白部分.也当是失去焦点了.