W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:設(shè)定一個(gè)定時(shí)器,按照指定的周期(以毫秒計(jì))來(lái)執(zhí)行注冊(cè)的回調(diào)函數(shù)。
Function callback, Number delay
callback
參數(shù)說(shuō)明 :回調(diào)函數(shù)
delay
參數(shù)說(shuō)明 : 執(zhí)行回調(diào)函數(shù)之間的時(shí)間間隔,單位 ms。
名稱 | 解釋 |
---|---|
number |
定時(shí)器的編號(hào)。這個(gè)值可以傳遞給 clearInterval 來(lái)取消該定時(shí)。 |
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
<view>Interval</view>
<view>{{Interval}}</view>
</view>
<button type="primary" bindtap="bindSetInterval">setInterval</button>
<button type="primary" bindtap="bindClearInterval">clearInterval</button>
</view>
<view class="card-area">
<view class="top-description border-bottom">
<view>timeout</view>
<view>{{timeout}}</view>
</view>
<button type="primary" bindtap="bindSetTimeout">setTimeout</button>
<button type="primary" bindtap="bindClearTimeout">clearTimeout</button>
</view>
</view>
Page({
data: {
Interval: 0,
timeout: 0
},
bindSetTimeout() {
this.timeout && clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
swan.showToast({
title: 'timeout',
icon: 'none'
});
this.setData({
timeout: 3
})
}, 3000);
},
bindClearTimeout() {
this.timeout && clearTimeout(this.timeout);
this.setData({
timeout: 0
})
},
bindSetInterval() {
this.interval && clearInterval(this.interval);
this.interval = setInterval(() => {
swan.showToast({
title: 'setInterval',
icon: 'none'
});
this.data.Interval += 3;
this.setData({
Interval: this.data.Interval
})
}, 3000);
},
bindClearInterval() {
this.interval && clearInterval(this.interval);
this.setData({
Interval: 0
})
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: