这篇翻译不完整。请帮忙从英语翻译这篇文章

NodeIterator 接口表示一个遍历 DOM 子树中节点列表的成员的迭代器。节点将按照文档顺序返回。

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

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

属性

这个接口不会继承任何属性。

NodeIterator.root 只读
返回一个Node ,它代表创建 NodeIterator 时指定的根节点。
NodeIterator.whatToShow 只读
返回一个无符号长整型,它是一个由描述必须呈现的Node类型的常量构成的位掩码。不匹配的节点被跳过,但是如果相关,他们的子节点可能被包括在内。可能的值是:
Constant Numerical value Description
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 with an 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 显示Comment 节点。
NodeFilter.SHOW_DOCUMENT 256 显示Document 节点。
NodeFilter.SHOW_DOCUMENT_FRAGMENT 1024

显示DocumentFragment节点。

NodeFilter.SHOW_DOCUMENT_TYPE 512 显示DocumentType 节点。
NodeFilter.SHOW_ELEMENT 1 显示Element 节点。
NodeFilter.SHOW_ENTITY 32 Shows Entity nodes. This is meaningful only when creating a NodeIterator with an 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 Shows Notation nodes. This is meaningful only when creating a NodeIterator with a 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 显示Text 节点。
NodeIterator.filter 只读
Returns a NodeFilter used to select the relevant nodes.
NodeIterator.expandEntityReferences 只读
Is a Boolean indicating if, when discarding an EntityReference its whole sub-tree must be discarded at the same time.
NodeIterator.referenceNode 只读
Returns the Node to which the iterator is anchored.
NodeIterator.pointerBeforeReferenceNode 只读
Returns a Boolean flag that indicates whether the NodeIterator is anchored before, the flag being true, or after, the flag being false, the anchor node.

方法

这个接口不会继承任何属性。

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 Node in the document, or null if there are none.
NodeIterator.nextNode()
Returns the next Node in the document, or null if there are none.

特性

Specification Status Comment
DOM
NodeIterator
Living Standard Added the referenceNode and pointerBeforeReferenceNode properties.
Removed the expandEntityReferences property.
The method detach() has been changed to be a no-op.
The methods previousNode() and nextNode() don't raise an exception any more.
Document Object Model (DOM) Level 2 Traversal and Range Specification
NodeIterator
Obsolete Initial definition.

浏览器兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 (Yes) 3.5 (1.9.1) 9.0 9.0 3.0
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 1.0 (1.9.1) (Yes) 9.0 3.0

扩展阅读

文档标签和贡献者

标签: 
 此页面的贡献者: hawtim
 最后编辑者: hawtim,