我们的志愿者还没有将这篇文章翻译为 中文 (简体)。加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。
The TreeWalker.filter read-only property returns a NodeFilter that is the filtering object associated with the TreeWalker.
When creating the TreeWalker, the filter object is passed in as the third parameter, and its method NodeFilter.acceptNode() is called on every single node to determine whether or not to accept it.
Syntax
nodeFilter = treeWalker.filter;
Example
var treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
false
);
nodeFilter = treeWalker.filter; // document.body in this case
Specifications
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'TreeWalker.filter' in that specification. |
Living Standard | No change from Document Object Model (DOM) Level 2 Traversal and Range Specification |
| Document Object Model (DOM) Level 2 Traversal and Range Specification The definition of 'TreeWalker.filter' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 1.0 | (Yes) | 2.0 (1.8.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.8.1) | (Yes) | 9.0 | 3.0 |
See also
- The
TreeWalkerinterface it belongs to.