最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于JQuery.timer插件實現(xiàn)一個計時器

 更新時間:2010年04月25日 16:49:37   作者:  
基于JQuery.timer插件實現(xiàn)一個計時器,需要的朋友可以參考下。
先去官網(wǎng)下載jQuery Timers插件 ,然后引用到html中。這里是1.2 version
復制代碼 代碼如下:

<script src="../Javascripts/Plugins/jquery.timers-1.2.js" type="text/javascript"></script>

  然后是HTML,我們可以放一個hidden 的server control存值用,當然這個隨你了。
復制代碼 代碼如下:

<asp:HiddenField ID="hicurrenttime" runat="server" />
<h1>
jQuery Timers Test</h1>
<input type="button" id="btnmaster" value="StartTimer" />
<h2>
Demos</h2>
<div class="demos">
<span id="durationtimerspan"></span>
<br />
<input id="txtresult" type="text" />
</div>

  加上JS:
[/code]
$(document).ready(function() {
var countnum = <%=hicurrenttime.Value %>;
$('#btnmaster').toggle(
function() {
$(this).val('StopTimer');
$('#durationtimerspan').everyTime(1000, 'testtimer', function(i) {
countnum = countnum + 1;
$(this).html('Duration: ' + countnum);
$('#<%=hicurrenttime.ClientID %>').val(countnum);
});
},
function() {
$(this).val('StartTimer');
$('#durationtimerspan').stopTime('testtimer');
$('#txtresult').val(countnum);
});
});
[html]
上面的代碼關(guān)鍵的地方是我們用toggle函數(shù),去實現(xiàn)點擊Button開關(guān)計時器。這個插件有三個方法:
everyTime(interval : Integer | String, [label = interval : String], fn : Function, [times = 0 : Integer])
每次都執(zhí)行
oneTime(interval : Integer | String, [label = interval : String], fn : Function)
執(zhí)行一次
stopTime([label : Integer | String], [fn : Function])
停止
最后我們效果如下圖: 
 
類似的用法:
復制代碼 代碼如下:

//每1秒執(zhí)行函式test()
function test(){
//do something...
}
$('body').everyTime('1s',test);
//每1秒執(zhí)行
$('body').everyTime('1s',function(){
//do something...
});
//每1秒執(zhí)行,并命名計時器名稱為A
$('body').everyTime('1s','A',function(){
//do something...
});
//每20秒執(zhí)行,最多5次,并命名計時器名稱為B
$('body').everyTime('2das','B',function(){
//do something...
},5);
//每20秒執(zhí)行,無限次,并命名計時器名稱為C
//若時間間隔抵到,但函式程序仍未完成則需等待執(zhí)行函式完成后再繼續(xù)計時
$('body').everyTime('2das','C',function(){
//執(zhí)行一個會超過20秒以上的程式
},0,true);
/***********************************************************
* oneTime(時間間隔, [計時器名稱], 呼叫的函式)
***********************************************************/
//倒數(shù)10秒后執(zhí)行
$('body').oneTime('1das',function(){
//do something...
});
//倒數(shù)100秒后執(zhí)行,并命名計時器名稱為D
$('body').oneTime('1hs','D',function(){
//do something...
});
/************************************************************
* stopTime ([計時器名稱], [函式名稱])
************************************************************/
//停止所有的在$('body')上計時器
$('body').stopTime ();
//停止$('body')上名稱為A的計時器
$('body').stopTime ('A');
//停止$('body')上所有呼叫test()的計時器
$('body').stopTime (test);

希望這篇POST對您有幫助。Author: Petter Liu

相關(guān)文章

最新評論

健康| 谢通门县| 榆林市| 肥东县| 华宁县| 银川市| 泽普县| 滨州市| 余干县| 日喀则市| 高雄市| 大厂| 闸北区| 霸州市| 徐州市| 彰化市| 花莲市| 洪雅县| 庐江县| 康保县| 吉隆县| 丁青县| 鹿邑县| 海阳市| 沛县| 清水县| 巨野县| 青冈县| 故城县| 田阳县| 集安市| 泸定县| 榆社县| 九龙坡区| 龙游县| 南江县| 鄂尔多斯市| 江口县| 河北省| 玉环县| 宁明县|