aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mutationobserver/takerecords/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/mutationobserver/takerecords/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/mutationobserver/takerecords/index.html')
-rw-r--r--files/zh-cn/web/api/mutationobserver/takerecords/index.html81
1 files changed, 81 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/mutationobserver/takerecords/index.html b/files/zh-cn/web/api/mutationobserver/takerecords/index.html
new file mode 100644
index 0000000000..b6ad1c65fc
--- /dev/null
+++ b/files/zh-cn/web/api/mutationobserver/takerecords/index.html
@@ -0,0 +1,81 @@
+---
+title: MutationObserver.takeRecords()
+slug: Web/API/MutationObserver/takeRecords
+translation_of: Web/API/MutationObserver/takeRecords
+---
+<div>{{APIRef("DOM WHATWG")}}</div>
+
+<p><span class="seoSummary">{{domxref("MutationObserver")}} 的 <code><strong>takeRecords()</strong></code> 方法返回已检测到但尚未由观察者的回调函数处理的所有匹配DOM更改的列表,使变更队列保持为空。</span> 此方法最常见的使用场景是在断开观察者之前立即获取所有未处理的更改记录,以便在停止观察者时可以处理任何未处理的更改。</p>
+
+<ul>
+</ul>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>mutationRecords</em> = <em>mutationObserver</em>.takeRecords()
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>无。</p>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回一个{{domxref("MutationRecord")}} 对象列表,每个对象都描述了应用于DOM树某部分的一次改动。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 调用<code>takeRecords()</code>后,已发生但未传递给回调的变更队列将保留为空。</p>
+</div>
+
+<h2 id="示例">示例</h2>
+
+<p>下面的示例展示了在断开观察者之前如何通过调用<code>takeRecords()</code>来处理任何未传递的{{domxref("MutationRecord")}}。</p>
+
+<pre class="brush: js; highlight:[12-18]">var targetNode = document.querySelector("#someElement");
+var observerOptions = {
+ childList: true,
+ attributes: true
+}
+
+var observer = new MutationObserver(callback);
+observer.observe(targetNode, observerOptions);
+
+/* ...later, when it's time to stop observing... */
+
+/* handle any still-pending mutations */
+
+var mutations = observer.takeRecords();
+
+if (mutations) {
+ callback(mutations);
+}
+
+observer.disconnect();
+</pre>
+
+<p>代码中第12-17行抓取了所有未处理的变更记录,然后调用回调,并将变更记录列表传递给回调,以保证所有变更记录都被处理。这是在调用{{domxref("MutationObserver.disconnect", "disconnect()")}}之前完成的,以便停止观察DOM。 </p>
+
+<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-takerecords', 'MutationObserver.takeRecords()')}}</td>
+ <td>{{ Spec2('DOM WHATWG') }}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.MutationObserver.takeRecords")}}</p>