aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/clearinterval/index.html
blob: 3ba4544b4b0249f153b48fba82f17f2e37d9bf88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: WindowTimers.clearInterval()
slug: Web/API/clearInterval
tags:
  - API
  - WindowOrWorkerGlobalScope
  - 参考
  - 方法
translation_of: Web/API/WindowOrWorkerGlobalScope/clearInterval
original_slug: Web/API/WindowOrWorkerGlobalScope/clearInterval
---
<div>{{ApiRef("HTML DOM")}}</div>

<p>{{domxref("WindowOrWorkerGlobalScope")}} mixin 的 <strong><code>clearInterval()</code></strong> 方法可取消先前通过 {{domxref("WindowOrWorkerGlobalScope.setInterval", "setInterval()")}} 设置的重复定时任务。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>scope</em>.clearInterval(<var>intervalID</var>)
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>intervalID</code></dt>
 <dd>要取消的定时器的 ID。是由 <code>setInterval()</code> 返回的。</dd>
</dl>

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

<h3 id="返回值">返回值</h3>

<p>{{jsxref("undefined")}}</p>

<h2 id="示例">示例</h2>

<p>查看 <a href="/en-US/docs/DOM/window.setInterval#Example"><code>setInterval()</code> 的示例</a></p>

<h2 id="Specification" name="Specification">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'webappapis.html#dom-clearinterval', 'WindowOrWorkerGlobalScope.clearInterval()')}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>Method moved to the <code>WindowOrWorkerGlobalScope</code> mixin in the latest spec.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'webappapis.html#dom-clearinterval', 'clearInterval()')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.WindowOrWorkerGlobalScope.clearInterval")}}</p>

<h2 id="参见">参见</h2>

<ul>
 <li><a href="/en-US/docs/JavaScript/Timers" title="JavaScript/Timers">JavaScript 定时器</a></li>
 <li>{{domxref("WindowOrWorkerGlobalScope.setTimeout")}}</li>
 <li>{{domxref("WindowOrWorkerGlobalScope.setInterval")}}</li>
 <li>{{domxref("WindowOrWorkerGlobalScope.clearTimeout")}}</li>
 <li>{{domxref("Window.requestAnimationFrame")}}</li>
 <li><a href="/en-US/docs/JavaScript/Timers/Daemons" title="JavaScript/Timers/Daemons"><em>Daemons</em> management</a></li>
</ul>