diff options
author | MDN <actions@users.noreply.github.com> | 2021-09-01 00:52:00 +0000 |
---|---|---|
committer | MDN <actions@users.noreply.github.com> | 2021-09-01 00:52:00 +0000 |
commit | af3288b106f44aaaa2c80d499ec669383d6f7203 (patch) | |
tree | 6d5a402249e4e8a83820c2592887062ec9202d79 /files/zh-cn/web/api/cleartimeout | |
parent | 1768b43f574673545e1f2a20e92a27b050a2bb53 (diff) | |
download | translated-content-af3288b106f44aaaa2c80d499ec669383d6f7203.tar.gz translated-content-af3288b106f44aaaa2c80d499ec669383d6f7203.tar.bz2 translated-content-af3288b106f44aaaa2c80d499ec669383d6f7203.zip |
[CRON] sync translated content
Diffstat (limited to 'files/zh-cn/web/api/cleartimeout')
-rw-r--r-- | files/zh-cn/web/api/cleartimeout/index.html | 151 |
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> |