【问题标题】:Advanced CSS/Jquery selector高级 CSS/Jquery 选择器
【发布时间】:2015-03-07 07:37:00
【问题描述】:

我有以下元素:

<div customAttribute="1" > element 1 </div>
<div customAttribute="1-1" > element 1-1 </div>
<div customAttribute="1-1-1" > element 1-1-1 </div>
<div customAttribute="1-1-2" > element 1-1-2 </div>
<div customAttribute="1-2" > element 1-2 </div>

如何使用 customAttribute 获取所有元素

1-1,
1-2,
...
1-n

但不是

1-1-1,
1-1-2,
...
1-1-n

使用 CSS 选择器?

【问题讨论】:

标签: jquery css jquery-selectors css-selectors


【解决方案1】:

据我了解,您可以使用div[customAttribute^='1-']:not([customAttribute^='1-1-'])。 如您所见,这将适用于 jquery 和 css: http://jsfiddle.net/597y2e6r/1/

如果不是这种情况,您需要更复杂的模式匹配 css 可能不是最好的工具...您可以改用 filter

【讨论】:

  • 如果有1-2-n 元素和1-n-n 元素,那么除了根据需要重复尽可能多的:not()s 之外别无他法。如果不以某种方式修改 HTML,过滤器路由将是最好的。
猜你喜欢
  • 2010-10-26
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多