gpt4 book ai didi

jquery - CSS/JQuery 选择器 : Is there anyway to select classes in classes?

转载 作者:行者123 更新时间:2023-12-01 02:21:45 24 4
gpt4 key购买 nike

假设我们有以下标记:

<div class="t-shirt black blue">Example</div>
<div class="t-shirt white blue">Example</div>
<div class="sweater black blue">Example</div>
<div class="sweater black red">Example</div>
<div class="sweater white red">Example</div>
<div class="hat black blue">Example</div>
<div class="hat black red">Example</div>
<div class="hat white red">Example</div>

有没有办法用一个选择器选择黑色和蓝色的T恤毛衣?我的意思是,不使用逗号分隔的选择器。

例如,我不想执行以下操作:

var wanted = $('.t-shirt.black.blue, .sweater.black.blue');

有没有办法做类似下面的事情? (我知道这不起作用):

var wanted = $('(.t-shirt, .sweater).black.blue');

提前致谢。

最佳答案

不,没有。既不在 jQuery 中,也不在 CSS 中。

即使有一个功能伪类用于对选择器的各个部分进行分组(例如选择器 4 中即将推出的 :matches()),您仍然需要提供这些类的逗号分隔列表:

:matches(.t-shirt, .sweater).black.blue

不用说,上面的选择器在任何浏览器中都不起作用。你可以implement it yourself as a Sizzle extension如果你真的愿意的话,但老实说我不会打扰。

关于jquery - CSS/JQuery 选择器 : Is there anyway to select classes in classes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15958876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com