亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

setinterval()與clearInterval()JS函數(shù)的調(diào)用方法

 更新時(shí)間:2015年01月21日 11:12:13   投稿:shichen2014  
這篇文章主要介紹了setinterval()與clearInterval()JS函數(shù)的調(diào)用方法,實(shí)例分析了setinterval()與clearInterval()的語(yǔ)法結(jié)構(gòu)及使用技巧,需要的朋友可以參考下

本文實(shí)例講述了setinterval()與clearInterval()JS函數(shù)的調(diào)用方法。分享給大家供大家參考。具體如下:

復(fù)制代碼 代碼如下:
<!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>setinterval()與clearInterval()用法</title> 
    <script type="text/javascript"> 
        function f1() { 
            alert("調(diào)用f1"); 
        } 
        function f2() { 
            alert("調(diào)用f2"); 
        } 
 
        function bodymousedown() { 
            alert("你好"); 
            alert("我好"); 
 
        } 
        function com() { 
            if (confirm("是否進(jìn)入")) { 
                alert("進(jìn)入了"); 
            } 
            else { 
                alert("退出"); 
            } 
        } 
        var interval; 
        function getinterval() { 
            if (confirm("確定要執(zhí)行嗎?")) { 
                 
                interval = setInterval("alert('每隔2000毫秒執(zhí)行一次')", 2000); 
            } 
            else { 
                alert("不執(zhí)行"); 
            } 
        } 
        function setTimeOut1() { 
            setTimeout("alert('3000毫秒后執(zhí)行這段代碼')", 3000); 
        } 
 
    </script> 
</head> 
<!--" -->  
<!--<body onmousedown ="bodymousedown()">--> 
<body> 
<!--ondblclick是雙擊事件,onclick是單擊事件--> 
<input type="button" onclick="document.ondblclick=f1" value="關(guān)聯(lián)事件1" />
<input type="button" onclick="document.ondblclick=f2" value="關(guān)聯(lián)事件2" />
 
<input type="button" ondblclick="bodymousedown()" value="調(diào)用函數(shù)" /> 
<input type="button" onclick="com()" value="confirm的用法" /> 
<input type="button" onclick="getinterval()" value="setInterval的用法,每隔一段時(shí)間執(zhí)行指定的代碼" /> 
 
<!--clearInterval取消setInterval的定時(shí)執(zhí)行,相當(dāng)于Timer中的Enabled=False--> 
<input type="button" onclick="clearInterval(interval)" value="取消執(zhí)行setinterval代碼" /> 
 
<input type="button" onclick="setTimeOut1()" value="setTimeOut,某個(gè)時(shí)間執(zhí)行代碼" /> 
 
</body> 
</html>

setInterval() 方法可按照指定的周期(以毫秒計(jì))來(lái)調(diào)用函數(shù)或計(jì)算表達(dá)式。
setInterval() 方法會(huì)不停地調(diào)用函數(shù),直到 clearInterval() 被調(diào)用或窗口被關(guān)閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數(shù)。
語(yǔ)法

復(fù)制代碼 代碼如下:
setInterval(code,millisec[,"lang"])

參數(shù) 描述
code 必需。要調(diào)用的函數(shù)或要執(zhí)行的代碼串。
millisec 必須。周期性執(zhí)行或調(diào)用 code 之間的時(shí)間間隔,以毫秒計(jì)。

setTimeout只運(yùn)行一次,也就是說(shuō)設(shè)定的時(shí)間到后就觸發(fā)運(yùn)行指定代碼,運(yùn)行完后即結(jié)束。
setinterval是循環(huán)運(yùn)行的,即每到設(shè)定時(shí)間間隔就觸發(fā)指定代碼。這是真正的定時(shí)器。

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論