aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mutationobserver/disconnect/index.html
blob: 7de675ca816b5750fb727ae4bb093ef00e754434 (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
---
title: MutationObserver.disconnect()
slug: Web/API/MutationObserver/disconnect
translation_of: Web/API/MutationObserver/disconnect
---
<div>{{APIRef("DOM WHATWG")}}</div>

<p><span class="seoSummary">{{domxref("MutationObserver")}} 的 <code><strong>disconnect()</strong></code> 方法告诉观察者停止观察变动。</span> 可以通过调用其{{domxref("MutationObserver.observe", "observe()")}}方法来重用观察者。</p>

<ul>
</ul>

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

<pre class="syntaxbox"><em>mutationObserver</em>.disconnect()
</pre>

<h3 id="参数">参数</h3>

<p>无。</p>

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

<p><code>undefined</code>.</p>

<div class="note">
<p><strong>注意:</strong> 所有已经检测到但是尚未向观察者报告的变动都会被丢弃。</p>
</div>

<h2 id="使用说明">使用说明</h2>

<p>如果被观察的元素被从DOM中移除,然后被浏览器的垃圾回收机制释放,此<code>MutationObserver</code>将同样被删除。</p>

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

<p>下面的示例创建了一个观察者,接着与之断开连接,让它可以重复使用。</p>

<pre class="brush: js">var targetNode = document.querySelector("#someElement");
var observerOptions = {
  childList: true,
  attributes: true
}

var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);

/* some time later... */

observer.disconnect();</pre>

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

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">批注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-mutationobserver-disconnect', 'MutationObserver.disconnect()')}}</td>
   <td>{{ Spec2('DOM WHATWG') }}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("api.MutationObserver.disconnect")}}</p>