WindowTimers.clearInterval()

WindowOrWorkerGlobalScope mixin 的 clearInterval() 方法可取消先前通过 setInterval() 设置的重复定时任务。

语法

scope.clearInterval(intervalID)

Parameters

intervalID
要取消的定时器的 ID。是由 setInterval() 返回的。

值得一提的是,setInterval()setTimeout() 共用其定义的 IDs,即可以使用 clearInterval() 和 clearTimeout() 中的任意一个。然而,为了使代码可读性更强,你应该尽量避免这种用法。

返回值

undefined

示例

查看 setInterval() 的示例

规范

规范 状态 备注
HTML Living Standard
WindowOrWorkerGlobalScope.clearInterval()
Living Standard Method moved to the WindowOrWorkerGlobalScope mixin in the latest spec.
HTML Living Standard
clearInterval()
Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
clearIntervalChrome Full support 4Edge Full support 12Firefox Full support 1
Full support 1
Full support 52
Notes
Notes clearInterval() now defined on WindowOrWorkerGlobalScope mixin.
IE Full support 4
Notes
Full support 4
Notes
Notes From Internet Explorer 4 through 8, clearInterval is an Object rather than a Function. This behavior was fixed in Internet Explorer 9.
Opera Full support 4Safari Full support 4WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4
Full support 4
Full support 52
Notes
Notes clearInterval() now defined on WindowOrWorkerGlobalScope mixin.
Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0

Legend

Full support  
Full support
See implementation notes.
See implementation notes.

参见