aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/nodeiterator
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/nodeiterator
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/nodeiterator')
-rw-r--r--files/zh-cn/web/api/nodeiterator/index.html214
1 files changed, 214 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/nodeiterator/index.html b/files/zh-cn/web/api/nodeiterator/index.html
new file mode 100644
index 0000000000..2b2795b6a0
--- /dev/null
+++ b/files/zh-cn/web/api/nodeiterator/index.html
@@ -0,0 +1,214 @@
+---
+title: NodeIterator
+slug: Web/API/NodeIterator
+tags:
+ - API
+ - DOM
+translation_of: Web/API/NodeIterator
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p><strong><code>NodeIterator</code></strong> 接口表示一个遍历 DOM 子树中节点列表的成员的迭代器。节点将按照文档顺序返回。</p>
+
+<p>NodeIterator可以使用{{domxref("Document.createNodeIterator()")}} 方法创建,如下所示:</p>
+
+<pre class="brush: js">var nodeIterator = document.createNodeIterator(<em>root</em>, <em>whatToShow</em>, <em>filter</em>);</pre>
+
+<h2 id="Properties" name="Properties">属性</h2>
+
+<p><em>这个接口不继承任何属性。</em></p>
+
+<dl>
+ <dt>{{domxref("NodeIterator.root")}} {{readonlyInline}}</dt>
+ <dd>返回一个{{domxref("Node")}} ,它代表创建 NodeIterator 时指定的根节点。</dd>
+ <dt>{{domxref("NodeIterator.whatToShow")}} {{readonlyInline}}</dt>
+ <dd>返回一个无符号长整型,它是一个由描述必须呈现的{{domxref("Node")}}类型的常量构成的位掩码。不匹配的节点被跳过,但是如果相关,他们的子节点可能被包括在内。可能的值是:
+ <table class="standard-table">
+ <tbody>
+ <tr>
+ <td class="header">Constant</td>
+ <td class="header">Numerical value</td>
+ <td class="header">Description</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_ALL</code></td>
+ <td><code>-1</code> (that is the max value of <code>unsigned long</code>)</td>
+ <td>显示所有节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_ATTRIBUTE</code> {{obsolete_inline}}</td>
+ <td><code>2</code></td>
+ <td>显示属性 {{ domxref("Attr") }} 节点. 只有当用一个 {{ domxref("Attr") }} 节点作为根节点来创建 {{ domxref("NodeIterator") }} 时才有意义; 在这种情况下, 这意味着属性节点会出现在迭代或遍历的首位. 因为属性永远不会是其它节点的子节点, 当遍历整个文档树时它们不会出现.</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_CDATA_SECTION</code> {{obsolete_inline}}</td>
+ <td><code>8</code></td>
+ <td>显示{{ domxref("CDATASection") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_COMMENT</code></td>
+ <td><code>128</code></td>
+ <td>显示{{ domxref("Comment") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_DOCUMENT</code></td>
+ <td><code>256</code></td>
+ <td>显示{{ domxref("Document") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_DOCUMENT_FRAGMENT</code></td>
+ <td><code>1024</code></td>
+ <td>
+ <p>显示{{ domxref("DocumentFragment") }}节点。</p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_DOCUMENT_TYPE</code></td>
+ <td><code>512</code></td>
+ <td>显示{{ domxref("DocumentType") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_ELEMENT</code></td>
+ <td><code>1</code></td>
+ <td>显示{{ domxref("Element") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_ENTITY</code> {{obsolete_inline}}</td>
+ <td><code>32</code></td>
+ <td>显示 {{ domxref("Entity") }} 节点. 只有当用一个 {{ domxref("Entity") }} 节点作为它的根节点来创建一个 {{ domxref("NodeIterator") }} 时才有意义; 在这种情况下,  {{ domxref("Entity") }} 节点会出现在迭代或遍历的首位. 因为 {{ domxref("Entity") }}  永远不会是其它节点的子节点, 当遍历整个文档树时它们不会出现.</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_ENTITY_REFERENCE</code> {{obsolete_inline}}</td>
+ <td><code>16</code></td>
+ <td>显示{{ domxref("EntityReference") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_NOTATION</code> {{obsolete_inline}}</td>
+ <td><code>2048</code></td>
+ <td>显示 {{ domxref("Notation") }} 节点. 只有当用一个 {{ domxref("Notation") }} 节点作为它的根节点时来创建一个 {{ domxref("NodeIterator") }} 才有意义; 在这种情况下,  {{ domxref("Notation") }} 节点会出现在迭代或遍历的首位. 因为 {{ domxref("Notation") }}  永远不会是其它节点的子节点, 当遍历整个文档树时它们不会出现.</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_PROCESSING_INSTRUCTION</code></td>
+ <td><code>64</code></td>
+ <td>显示{{ domxref("ProcessingInstruction") }} 节点。</td>
+ </tr>
+ <tr>
+ <td><code>NodeFilter.SHOW_TEXT</code></td>
+ <td><code>4</code></td>
+ <td>显示{{ domxref("Text") }} 节点。</td>
+ </tr>
+ </tbody>
+ </table>
+ </dd>
+ <dt>{{domxref("NodeIterator.filter")}} {{readonlyInline}}</dt>
+ <dd>返回一个用来选择相关节点的 {{domxref("NodeFilter")}} .</dd>
+ <dt>{{domxref("NodeIterator.expandEntityReferences")}} {{readonlyInline}} {{deprecated_inline}}</dt>
+ <dd>Is a {{domxref("Boolean")}} indicating if, when discarding an {{domxref("EntityReference")}} its whole sub-tree must be discarded at the same time.</dd>
+ <dt>{{domxref("NodeIterator.referenceNode")}} {{readonlyInline}} {{experimental_inline() }}</dt>
+ <dd>返回当前遍历到的 {{domxref("Node")}} .</dd>
+ <dt>{{domxref("NodeIterator.pointerBeforeReferenceNode")}} {{readonlyInline}} {{ experimental_inline() }}</dt>
+ <dd>Returns a {{domxref("Boolean")}} flag that indicates whether the {{domxref("NodeIterator")}} is anchored before, the flag being <code>true</code>, or after, the flag being <code>false</code>, the anchor node.</dd>
+</dl>
+
+<h2 id="Methods" name="Methods">方法</h2>
+
+<p><em>这个接口不会继承任何属性。</em></p>
+
+<dl>
+ <dt>{{domxref("NodeIterator.detach()")}} {{obsolete_inline()}}</dt>
+ <dd>这个方法不是必需的. 它现在什么也不做. 之前用来告诉引擎,<code>NodeIterator</code> 已经不会再使用,现在已经不做任何事情.</dd>
+ <dt>{{domxref("NodeIterator.previousNode()")}}</dt>
+ <dd>返回前一个 {{domxref("Node")}} ,如果不存在则返回 <code>null</code>.</dd>
+ <dt>{{domxref("NodeIterator.nextNode()")}}</dt>
+ <dd>返回下一个 {{domxref("Node")}} , 如果不存在则返回<code>null</code> .</dd>
+</dl>
+
+<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('DOM WHATWG', '#nodeiterator', 'NodeIterator')}}</td>
+ <td>{{Spec2('DOM WHATWG')}}</td>
+ <td>Added the <code>referenceNode</code> and <code>pointerBeforeReferenceNode</code> properties.<br>
+ Removed the <code>expandEntityReferences</code> property.<br>
+ The method <code>detach()</code> has been changed to be a no-op.<br>
+ The methods <code>previousNode()</code> and <code>nextNode()</code> don't raise an exception any more.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM2 Traversal_Range', 'traversal.html#Iterator-overview', 'NodeIterator')}}</td>
+ <td>{{Spec2('DOM2 Traversal_Range')}}</td>
+ <td>Initial definition.</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.9.1")}}</td>
+ <td>9.0</td>
+ <td>9.0</td>
+ <td>3.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>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>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("1.9.1")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>9.0</td>
+ <td>3.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="扩展阅读">扩展阅读</h2>
+
+<ul>
+ <li>The creator method: {{domxref("Document.createNodeIterator()")}}.</li>
+ <li>Related interfaces: {{domxref("NodeFilter")}}, {{domxref("TreeWalker")}}.</li>
+</ul>
+
+<p>
+ <audio style="display: none;"> </audio>
+</p>