NodeIterator.whatToShow read-only property represents an unsigned integer representing a bitmask signifying what types of nodes should be returned by the NodeIterator .

句法

var nodeTypes = nodeIterator.whatToShow;
					

The values that can be combined to form the bitmask 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 NodeIterator or 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 NodeIterator or 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 NodeIterator or 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 展示 文本 节点。

范例

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

规范

规范 状态 注释
DOM
The definition of 'NodeIterator.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 'NodeIterator.whatToShow' 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
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

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: