W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋:取消由 setInterval 設(shè)置的定時器。
Number intervalID
intervalID
參數(shù)說明 :要取消的定時器的 ID。
<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號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: