我有一个页面,其标签<body onload="setInterval('window.location.reload()', 60000);">
导致页面每1分钟刷新一次。更改body onLoad on img点击
我想制作一个按钮(暂停),点击时取消刷新。
我曾尝试以下,但它不工作:
window.onload= function() {};
我有一个页面,其标签<body onload="setInterval('window.location.reload()', 60000);">
导致页面每1分钟刷新一次。更改body onLoad on img点击
我想制作一个按钮(暂停),点击时取消刷新。
我曾尝试以下,但它不工作:
window.onload= function() {};
在你的脚本:
var pid=false;
function clear()
{
clearInterval(pid);
pid=false;
}
function resume()
{
if(!pid)
pid=setInterval('window.location.reload()', 60000);
}
在身体
<body onload="pid=setInterval('window.location.reload()', 60000);">....
<button onclick="clear()">Pause</button>
<button onclick="resume()">Resume</button>....
您可以致电clearInterval()
这样
id = setInterval('func', time);
<button onlcick="clearInterval(id)">Pause</button>
clearInterval()
是在window
对象,它会清除的方法你setInterval()
Here's a link更多信息
u能请解释一下什么是** clearInterval()* * –
它的更好,如果你把你的脚本功能,让您可以拨打它也来自其他地方。
就像这个...
<html>
<head>
<script type="text/javascript">
var intervalRef;
function ResumeRefresh(interval){
intervalRef = setInterval('window.location.reload()', interval);
}
function StopRefresh(){
intervalRef=window.clearInterval(intervalRef);
}
</script>
</head>
<body onload="ResumeRefresh(60000);">
<input type="button" val="Stop Refreshing" onclick="StopRefresh();"></input>
</body>
你需要这样的事情:
<script>
var reloadInterval;
var run = true;
function setMyInterval()
{
reloadInterval = setInterval('window.location.reload()', 60000);
}
function Pause()
{
if(run)
{
clearInterval(reloadInterval);
}
else
{
reloadInterval = setInterval('window.location.reload()', 60000);
}
}
</script>
HTML:
<body onload = 'setMyInterval()'>
<button onlcick="Pause()">Pause/Play</button>
感谢它是工作,但如果我想再次激活它呢? –
@MarioSoft编辑答案.. – gopi1410