clearTimeout()
方法在
WindowOrWorkerGlobalScope
mixin cancels a timeout previously established by calling
setTimeout()
.
scope.clearTimeout(timeoutID)
timeoutID
setTimeout()
.
It's worth noting that the pool of IDs used by
setTimeout()
and
setInterval()
are shared, which means you can technically use
clearTimeout()
and
clearInterval()
interchangeably. However, for clarity, you should avoid doing so.
Run the script below in the context of a web page and click on the page once. You'll see a message popping up in a second. If you click the page multiple times in one second, the alert only appears once.
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);
}
};
window.onclick = function() { alarm.setup(); };
Passing an invalid ID to
clearTimeout()
silently does nothing; no exception is thrown.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'WindowOrWorkerGlobalScope.clearTimeout()' in that specification. |
实时标准 |
Method moved to the
WindowOrWorkerGlobalScope
mixin in the latest spec.
|
|
HTML 实时标准
The definition of 'clearTimeout()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
clearTimeout
|
Chrome 45 | Edge 12 |
Firefox
1
|
IE
4
|
Opera 4 | Safari 4 | WebView Android 45 | Chrome Android 45 |
Firefox Android
4
|
Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 5.0 |
完整支持
见实现注意事项。
WindowOrWorkerGlobalScope.setTimeout()
WindowOrWorkerGlobalScope.setInterval()
WindowOrWorkerGlobalScope.clearInterval()
Window.requestAnimationFrame()
WindowOrWorkerGlobalScope
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers