W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
WindowOrWorkerGlobalScope mixin的clearTimeout()方法取消先前通過調用setTimeout()建立的超時。
scope .clearTimeout(timeoutID)
timeoutID
setTimeout()
調用返回。
需要注意的是,setTimeout()和setInterval()使用的ID池是共享的,這意味著你可以在技術上使用clearTimeout()和clearInterval()互換。但是,為清晰起見,您應該避免這樣做。
在網頁上下文中運行下面的腳本,然后單擊該頁面一次。你會在一秒鐘內看到一條消息。如果您在一秒鐘內多次單擊該頁面,則警報僅出現一次。
var alarm = {
remind: function(aMessage) {
alert(aMessage);
this.timeoutID = undefined;
},
setup: function() {
if (typeof this.timeoutID === 'number') {
this.cancel();
}
this.timeoutID = window.setTimeout(function(msg) {
this.remind(msg);
}.bind(this), 1000, 'Wake up!');
},
cancel: function() {
window.clearTimeout(this.timeoutID);
this.timeoutID = undefined;
}
};
window.onclick = function() { alarm.setup(); };
將無效ID傳遞給clearTimeout()并且不做任何事情;沒有異常被拋出。
規(guī)范 | 狀態(tài) | 評論 |
---|---|---|
HTML Living Standard
該規(guī)范中“WindowOrWorkerGlobalScope.clearTimeout()”的定義
|
Living Standard
|
方法移動到最新規(guī)范中的WindowOrWorkerGlobalScope mixin
|
HTML Living Standard
該規(guī)范中'clearTimeout()'的定義
|
Living Standard
|
新的兼容性表格處于測試階段
電腦端 | 移動端 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome
|
Edge
|
火狐 | Internet Explorer
|
Opera
|
Safari
|
Android webview | Chrome for Android
|
Edge Mobile | Firefox for Android
|
Opera for Android
|
iOS Safari | |
基本支持 | 支持:1 | 支持 | 支持:1 | 支持:4 | 支持:4 | 支持:4 | 支持:1 | 支持:1 | 支持 | 支持:4 | 支持:6 | 支持:1 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯系方式:
更多建議: