aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/cleartimeout/index.html
diff options
context:
space:
mode:
authorMasahiro FUJIMOTO <mfujimot@gmail.com>2021-09-04 00:46:12 +0900
committerMasahiro FUJIMOTO <mfujimot@gmail.com>2021-09-04 00:46:12 +0900
commitfe6f6abf2b7c497bf1f97f73a82dde7cf48eb79f (patch)
tree51b7edfc370236684a203f4e69ae67bb7d24b549 /files/zh-cn/web/api/cleartimeout/index.html
parent04ea4edc83cc12142ed151bbea2c65cffc8e76f6 (diff)
parenteeb07fe338cdc90092841d717919f46f9d9e3ff9 (diff)
downloadtranslated-content-fe6f6abf2b7c497bf1f97f73a82dde7cf48eb79f.tar.gz
translated-content-fe6f6abf2b7c497bf1f97f73a82dde7cf48eb79f.tar.bz2
translated-content-fe6f6abf2b7c497bf1f97f73a82dde7cf48eb79f.zip
Merge branch 'main' into 20210818-Glossary/Type
Diffstat (limited to 'files/zh-cn/web/api/cleartimeout/index.html')
-rw-r--r--files/zh-cn/web/api/cleartimeout/index.html151
1 files changed, 151 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/cleartimeout/index.html b/files/zh-cn/web/api/cleartimeout/index.html
new file mode 100644
index 0000000000..30648c48b7
--- /dev/null
+++ b/files/zh-cn/web/api/cleartimeout/index.html
@@ -0,0 +1,151 @@
+---
+title: WindowOrWorkerGlobalScope.clearTimeout()
+slug: Web/API/clearTimeout
+tags:
+ - API
+ - WindowOrWorkerGlobalScope
+ - clearTimeout
+translation_of: Web/API/WindowOrWorkerGlobalScope/clearTimeout
+original_slug: Web/API/WindowOrWorkerGlobalScope/clearTimeout
+---
+<div>
+<div>{{APIRef("HTML DOM")}}</div>
+</div>
+
+<p>{{domxref("WindowOrWorkerGlobalScope")}}内置的<strong><code>clearTimeout()</code></strong>方法取消了先前通过调用{{domxref("WindowOrWorkerGlobalScope.setTimeout", "setTimeout()")}}建立的定时器。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="notranslate"><em>scope</em>.clearTimeout(<em>timeoutID</em>)</pre>
+
+
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>timeoutID</code></dt>
+ <dd>您要取消定时器的标识符。 该ID由相应的<code>setTimeout()</code>调用返回。</dd>
+</dl>
+
+<p>值得注意的是,{{domxref("WindowOrWorkerGlobalScope.setTimeout", "setTimeout()")}}和{{domxref("WindowOrWorkerGlobalScope.setInterval", "setInterval()")}}使用共享的ID池, 意味着在技术上可以混用<code>clearTimeout()</code>和{{domxref("WindowOrWorkerGlobalScope.clearInterval", "clearInterval()")}} 。 但是,为了清楚起见,你应该避免这样做。</p>
+
+<h2 id="Example" name="Example">示例</h2>
+
+<p>在一个网页中运行如下脚本,并且点击一次页面。一秒钟后你会看见弹出一条信息。如果你在一秒内不停点击页面,弹出框将不再出现。</p>
+
+<pre class="brush: js notranslate">var alarm = {
+ remind: function(aMessage) {
+ alert(aMessage);
+ delete this.timeoutID;
+ },
+
+ setup: function() {
+ this.cancel();
+ var self = this;
+ this.timeoutID = window.setTimeout(function(msg) {self.remind(msg);}, 1000, "Wake up!");
+ },
+
+ cancel: function() {
+ if(typeof this.timeoutID == "number") {
+ window.clearTimeout(this.timeoutID);
+ delete this.timeoutID;
+ }
+ }
+};
+window.onclick = function() { alarm.setup() };</pre>
+
+<h2 id="Notes" name="Notes">注意</h2>
+
+<p>传入一个错误的 ID 给 <code>clearTimeout()</code>不会有任何影响;也不会抛出异常。</p>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'webappapis.html#dom-cleartimeout', 'WindowOrWorkerGlobalScope.clearTimeout()')}}</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-cleartimeout', 'clearTimeout()')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容">浏览器兼容</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>1.0</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("1")}}<br>
+ {{CompatGeckoDesktop("52")}}<sup>[1]</sup></td>
+ <td>4.0</td>
+ <td>4.0</td>
+ <td>1.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>1.0</td>
+ <td>1.0</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("1")}}<br>
+ {{CompatGeckoMobile("52")}}<sup>[1]</sup></td>
+ <td>6.0</td>
+ <td>6.0</td>
+ <td>1.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] <code>clearTimeout()</code> now defined on {{domxref("WindowOrWorkerGlobalScope")}} mixin.</p>
+
+<h2 id="See_also" name="See_also">更多</h2>
+
+<ul>
+ <li>{{domxref("WindowTimers.setTimeout()")}}</li>
+ <li>{{domxref("WindowTimers.setInterval()")}}</li>
+ <li>{{domxref("WindowTimers.clearInterval()")}}</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>