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
节点
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()
节点
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()
节点
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()
节点
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()
节点
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()
节点
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()
节点
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()
节点
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. |
过时 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
弃用。不要用于新网站。
Document.createTreeWalker()
.
NodeFilter
,
NodeIterator
.
TreeWalker
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TypeInfo
USVString
UserDataHandler
XMLDocument