jQuery Timers 定時插件使用
JQuery Timers提供了三個函式
1. everyTime(時間間隔, [定時器名稱], 函式名稱, [次數限制], [等待函式程序完成])
2. oneTime(時間間隔, [定時器名稱], 呼叫的函式)
3. stopTime ([定時器名稱], [函式名稱])
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script src="jquery-1.4.2.js"></script> <script src="jquery.timers-1.1.2.js"></script> </head><body> <button id="btn1">每一秒執行 </button> <button id="btn2">清除每二秒執行 </button>
<button id="btn3">執行3次停止 </button> </body> </html> <script> /*
- everyTime(時間間隔, [計時器名稱], 函式名稱, [次數限制], [等待函式程序完成])
- oneTime(時間間隔, [計時器名稱], 呼叫的函式)
stopTime ([計時器名稱], [函式名稱]) / $(document).ready( function(){ /**每二秒執行**/ $("#btn1").click(function(){
$('body').everyTime('2s','ds1',function (){ console.log("每二秒執行"); });
}); /***每二秒執行**/
/***清除每二秒執行**/ $("#btn2").click(function(){
$('body').stopTime ('ds1'); console.log("已清除每二秒執行");
});
/***清除每二秒執行**/
/*******執行3次停止********/ $("#btn3").click(function(){ $('#btn3').everyTime('1s','ds2',function (){ console.log("執行3次停止"); },3); }); /*******執行3次停止********/
} ); </script></pre>
本文由用戶 xmp7 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!