我有一個頁面,其標籤<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