Window:clearInterval() 方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Window 接口的 clearInterval() 方法可取消先前通过调用 setInterval() 设置的重复定时任务。如果提供的参数未指定先前建立的操作,则此方法不执行任何动作。

语法

js
clearInterval(intervalID)

参数

intervalID

你要取消的重复操作的标识符。这个 ID 是由对应的 setInterval() 调用返回的。

值得一提的是,setInterval()setTimeout() 共享同一个 ID 池,并且 clearInterval()clearTimeout() 在技术上是可互换使用的。然而,为了清晰起见,你应该尽量避免这种用法。

返回值

无(undefined)。

示例

参见 setInterval() 以获取示例。

规范

Specification
HTML
# dom-clearinterval-dev

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
clearInterval
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support

参见