這就相當(dāng)于一個(gè)定時(shí)器;obj = setTimeout( 函數(shù)名稱 , 毫秒數(shù)); &nb..."/>
您好,登錄后才能下訂單哦!
1、其他函數(shù)
obj = setInterval('函數(shù)名稱', 毫秒數(shù)); clearInterval(obj); --->這就相當(dāng)于一個(gè)定時(shí)器;
obj = setTimeout('函數(shù)名稱', 毫秒數(shù)); clearTimeout(obj);
2、滾動(dòng)條
!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>頁面一</title> </head> <body> <hr/> <div style = 'width:500px;background-color:#ddd'> <div id = 'process' style = 'width:10%;height:10px;background-color:green;'></div> </div> <script type = 'text/javascript'> /* window.prb = 10; function Foo(){ var id = document.getElementById('process'); window.prb += 10; if(window.prb > 100){ clearInterval(window.interval); }else{ id.style.width = window.prb + '%'; } } window.interval = setInterval('Foo()', 500); //設(shè)置定時(shí)器 */ window.prb = 10; function Foo(){ var id = document.getElementById('process'); window.prb += 10; if(window.prb > 100){ clearTimeout(window.interval); }else{ id.style.width = window.prb + '%'; } } window.interval = setTimeout('Foo()', 500); </script> </body> </html>
運(yùn)行結(jié)果
3、×××燈
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>歡迎上級(jí)領(lǐng)導(dǎo)來校視察 </title> </head> <body> <input type = 'button' value = '關(guān)掉' onclick = 'stop();'/> <script type = 'text/javascript'> function Go(){ var content = document.title; //DOM獲得標(biāo)簽的內(nèi)容 var firstChar = content.charAt(0); var sub = content.substring(1, content.length); document.title = sub + firstChar; } interval = setInterval('Go()', 200); function stop(){ clearTimeout(interval); //停止當(dāng)前的程序運(yùn)行。 } </script> </body> </html>
運(yùn)行結(jié)果
4、總結(jié)
(1)、num = setInterval('事件函數(shù)', 毫秒),這個(gè)函數(shù)(setInterval)就是一個(gè)定時(shí)器,每隔多長(zhǎng)時(shí)間執(zhí)行一次這個(gè)函數(shù);
clearInterval(num),就是終止執(zhí)行定時(shí)器函數(shù);
(2)、num = setTimeout('事件函數(shù)', 毫秒),這個(gè)函數(shù)只執(zhí)行一次,就不在執(zhí)行;
clearTimeout(num),終止定時(shí)器的執(zhí)行;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。