TreeWalker.whatToShow read-only property returns an 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. 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 展示 文本 节点。

句法

nodeTypes = treeWalker.whatToShow;
					

范例

var treeWalker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_COMMENT + NodeFilter.SHOW_TEXT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
if( (treeWalker.whatToShow == NodeFilter.SHOW_ALL) ||
    (treeWalker.whatToShow % (NodeFilter.SHOW_COMMENT*2)) >= NodeFilter.SHOW_COMMENT) {
    // treeWalker will show comments
}
					

规范

规范 状态 注释
DOM
The definition of 'TreeWalker.whatToShow' in that specification.
实时标准 无变化自 Document Object Model (DOM) Level 2 Traversal and Range Specification
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'TreeWalker.whatToShow' 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
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

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: