是否可以实现如下搜索
document.querySelectorAll(selectors)
,但与一系列
Node
对象,而不是整个文档?
我有一个预先选定的列表
节点
对象,我想要一个函数
selectors
参数,但在数组中搜索。
基本上,这是一个是否有可能
node.match(selectors)
选中,以验证节点是否与选择器匹配,然后我可以简单地遍历节点列表。但我还没找到这种匹配检查是否可行。
所以我想要这样的东西:
function querySelectorInArray(nodeArray, selectors) {
return nodeArray.filter(function(node) {
return node.match(selectors); // this line is what I want, but dunno how
});
}
事后思考
不过,这是个好主意吗?我在想,
querySelectorAll
正在分析
选择器
只有一次,但我会对数组中的每个元素执行一次。会不会对表演不利或者有什么方法可以避免,比如预解析
选择器
把一个已知的物体传进来?