NodeIterator interface represents an iterator over the members of a list of the nodes in a subtree of the DOM. The nodes will be returned in document order.

句法

A NodeIterator 可以创建使用 Document.createNodeIterator() 方法,如下:

const nodeIterator = document.createNodeIterator(root, whatToShow, filter);
					

特性

此接口未继承任何特性。

NodeIterator.root 只读
返回 节点 representing the root node as specified when the NodeIterator was created.
NodeIterator.whatToShow 只读

返回 unsigned long being a bitmask made of constants describing the types of 节点 that must to be presented. Non-matching nodes are skipped, but their children may be included, if relevant.

可能的值包括:

常量 数值 描述
NodeFilter.SHOW_ALL -1 (that is the max value of unsigned long ) 展示所有节点。
NodeFilter.SHOW_ATTRIBUTE 2 Shows attribute Attr nodes. This is meaningful only when creating a NodeIterator 采用 Attr node as its root; in this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.
NodeFilter.SHOW_CDATA_SECTION 8 展示 CDATASection 节点。
NodeFilter.SHOW_COMMENT 128 展示 注释 节点。
NodeFilter.SHOW_DOCUMENT 256 展示 Document 节点。
NodeFilter.SHOW_DOCUMENT_FRAGMENT 1024 展示 DocumentFragment 节点。
NodeFilter.SHOW_DOCUMENT_TYPE 512 展示 DocumentType 节点。
NodeFilter.SHOW_ELEMENT 1 展示 元素 节点。
NodeFilter.SHOW_ENTITY 32 展示 Entity nodes. This is meaningful only when creating a NodeIterator 采用 Entity node as its root; in this case, it means that the Entity node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_ENTITY_REFERENCE 16 展示 EntityReference 节点。
NodeFilter.SHOW_NOTATION 2048 展示 Notation nodes. This is meaningful only when creating a NodeIterator 采用 Notation node as its root; in this case, it means that the Notation node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_PROCESSING_INSTRUCTION 64 展示 ProcessingInstruction 节点。
NodeFilter.SHOW_TEXT 4 展示 文本 节点。
NodeIterator.filter 只读
返回 NodeFilter 用于选择相关节点。
NodeIterator.expandEntityReferences 只读
布尔 indicating if, when discarding an EntityReference its whole sub-tree must be discarded at the same time.
NodeIterator.referenceNode 只读
返回 节点 to which the iterator is anchored.
NodeIterator.pointerBeforeReferenceNode 只读
返回 布尔 flag that indicates whether the NodeIterator is anchored before, the flag being true , or after, the flag being false , the anchor node.

方法

This interface doesn't inherit any method.

NodeIterator.detach()
This operation is a no-op. It doesn't do anything. Previously it was telling the engine that the NodeIterator was no more used, but this is now useless.
NodeIterator.previousNode()
Returns the previous 节点 in the document, or null if there are none.
NodeIterator.nextNode()
返回下一 节点 in the document, or null if there are none.

规范

规范 状态 注释
DOM
The definition of 'NodeIterator' in that specification.
实时标准 添加 referenceNode and pointerBeforeReferenceNode 特性。
移除 expandEntityReferences 特性。
方法 detach() has been changed to be a no-op.
方法 previousNode() and nextNode() don't raise an exception any more.
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'NodeIterator' in that specification.
过时 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
NodeIterator Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
detach 弃用 非标 Chrome 1 Edge 12 Firefox 3.5 — 22 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 — 22 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
expandEntityReferences 弃用 非标 Chrome 1 Edge 12 Firefox 3.5 — 21 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 — 21 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
filter Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
nextNode Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
pointerBeforeReferenceNode Chrome 1 Edge 17 Firefox 3.5 IE No Opera Yes Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS 3 Samsung Internet Android Yes
previousNode Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
referenceNode Chrome 1 Edge 17 Firefox 3.5 IE No Opera Yes Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS 3 Samsung Internet Android Yes
root Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
whatToShow Chrome 1 Edge 12 Firefox 3.5 IE 9 Opera 9 Safari 3 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

元数据

  • 最后修改: