好吧,所以我陷入了一个非常尴尬的境地,我试图为一套特定的规则创建一个选择器。
每个元素都有一系列的数据属性,我试图匹配一些,查询如下所示
select all elements where data-1 contains (any of these)
and with data-1 starts with this
and with data-1 starts with that
and with data-2 is this
and with data-3 is this
and with data-3 is this.这就是人类所说的,我遇到的问题是特定于查询的第一部分,我需要对一组ors进行有效的分组,然后抛出和结束
执行[data-1*="this"],[data-1*="that"][data-1^="thing"]会导致
select all elements where data-1 contains "this" or
select all elements where data-1 contains "that" and data-1 starts with "thing".有人能帮我弄清楚吗?将其作为一个查询而不是多个查询是理想的。
我想看到的是,([data-1*="this"],[data-1*="that"])[data-1^="thing"]可以有效地将ors分组到查询的单个部分,但是这是行不通的。
发布于 2014-07-17 12:25:26
我一点也不反对这些属性。更新元素数据(例如,$('.myclass').data('foo', 'bar')不更新属性)。属性设置元素数据的初始值,但仅此而已。
在您的情况下,我建议使用jQuerys过滤器函数。有点像
$('.some-class-common-to-all-candidates').filter(function(){
var d = $(this).data('1');
if( 'foo' == d ){
return true;
} else if( d > 10 ){
return true;
}
// If we get this far then no match
return false;
})没有经过测试,我创造了条件,但你应该得到要点。
jQuery过滤器文档
https://stackoverflow.com/questions/24803312
复制相似问题