Skip to content

求解答选择器中的 << 关系操作符用法 #299

Closed Answered by lisonge
jiuqianyuan asked this question in Q&A
Discussion options

You must be logged in to vote

深度优先先序遍历参考 querySelectorAll

任意页面打开浏览器控制台运行 document.querySelectorAll('*') 会输出一个类数组, order 就是这个顺序,这个 order 并不重要


<< 一般情况不怎么使用,主要是 <<n 搭配 quickFind 使用

这个快照 https://i.gkd.li/import/13264779 就是一个很好的例子

这个目标节点 [id="com.byted.pangle.m:id/tt_splash_skip_btn"] 由于不是 quickFind 的,我们只能一个一个手动遍历得到,查询速度就慢

但是其祖先节点 [id="com.coolapk.market:id/ad_container"] 是可以 quickFind 的,如果是旧版本的规则最多只能写

matches:[ '[id="com.coolapk.market:id/ad_container"]' , '[id!=null][id="com.byted.pangle.m:id/tt_splash_skip_btn"]']

虽然可以使用 quickFind 但是最后一个选择器仍然需要遍历所有节点,只是减少了无用查询,但是查询速度并没有增加

但是如果使用

[id="com.byted.pangle.m:id/tt_splash_skip_btn"] <<n [id="com.coolapk.market:id/ad_container"]

搭配 quickFind 使用就直接一步到位能判断和查询到目标节点

使用 <<n + quick…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jiuqianyuan
Comment options

@lisonge
Comment options

Answer selected by jiuqianyuan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants