DOM中的setInterval方法
setInterval() 方法可按照指定的周期(以毫秒計(jì))來調(diào)用函數(shù)或計(jì)算表達(dá)式。
setInterval() 方法會(huì)不停地調(diào)用函數(shù),直到 clearInterval() 被調(diào)用或窗口被關(guān)閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數(shù)。
?
clearInterval() 方法可取消由 setInterval() 設(shè)置的 timeout。
clearInterval() 方法的參數(shù)必須是由 setInterval() 返回的 ID 值。
?
?
?
例子:
?
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>演示文檔</title>
<script>
//生命全局變量intervalId
?var intervalId;
?function startInterval(){
??intervalId = setInterval("alert('helle')",5000);
?}
???
</script>
</head>
<body>
?<input type="button" value="點(diǎn)擊彈出hello對(duì)話框" οnclick="startInterval()" />
<input type="button" value="停止interval" οnclick="clearInterval(intervalId);"/>
</body>
</html>
總結(jié)
以上是生活随笔為你收集整理的DOM中的setInterval方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一份超级全面的PHP面试题
- 下一篇: DOM中setTimeout() 方法用