TreeWalker 对象表示文档子树节点及其位置。

A TreeWalker 可以创建使用 Document.createTreeWalker() 方法。

特性

此接口未继承任何特性。

TreeWalker.root 只读
返回 节点 representing the root node as specified when the TreeWalker was created.
TreeWalker.whatToShow 只读
返回 unsigned long being a bitmask made of constants describing the types of 节点 that must be presented. Non-matching nodes are skipped, but their children may be included, if relevant. The possible values are:
常量 数值 描述
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 TreeWalker 采用 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 TreeWalker 采用 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 TreeWalker 采用 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 展示 文本 节点。
TreeWalker.filter 只读
返回 NodeFilter 用于选择相关节点。
TreeWalker.expandEntityReferences 只读
布尔 indicating, when discarding an EntityReference its whole sub-tree must be discarded at the same time.
TreeWalker.currentNode
Is the 节点 on which the TreeWalker is currently pointing at.

方法

This interface doesn't inherit any method.

注意 : in the context of a TreeWalker , a node is visible if it exists in the logical view determined by the whatToShow and filter parameter arguments. (Whether or not the node is visible on the screen is irrelevant.)

TreeWalker.parentNode()
Moves the current 节点 to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
TreeWalker.firstChild()
Moves the current 节点 to the first visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, returns null and the current node is not changed.
TreeWalker.lastChild()
Moves the current 节点 to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, null is returned and the current node is not changed.
TreeWalker.previousSibling()
Moves the current 节点 to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
TreeWalker.nextSibling()
Moves the current 节点 to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
TreeWalker.previousNode()
Moves the current 节点 to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
TreeWalker.nextNode()
Moves the current 节点 to the next visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, returns null and the current node is not changed.

规范

规范 状态 注释
DOM
The definition of 'TreeWalker' in that specification.
实时标准 移除 expandEntityReferences 特性。
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'TreeWalker' in that specification.
过时 初始定义。

浏览器兼容性

The compatibility table on 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
TreeWalker Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
currentNode Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
expandEntityReferences 弃用 Chrome 1 Edge 12 Firefox 4 — 21 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 — 21 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
filter Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
firstChild Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
lastChild Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
nextNode Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
nextSibling Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
parentNode Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
previousNode Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
previousSibling Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
root Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes
whatToShow Chrome 1 Edge 12 Firefox 4 IE 9 Opera 9 Safari 3 WebView Android 3 Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS 3 Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

元数据

  • 最后修改: