我有一组div,例如:
<div class="wrapper">
<div class="uct_attr" data-tags="one two three four">stuff</div>
<div class="uct_attr" data-tags="three four">stuff</div>
<div class="uct_attr" data-tags="one three five">stuff</div>
<div class="uct_attr" data-tags="one two six">stuff</div>
<div class="uct_attr" data-tags="four five six">stuff</div>
</div?如何对与我的查询匹配的查询和不匹配的查询执行操作?请记住,我希望匹配属性数据标记中的一个单词
例如:
// if match 'one'
$('.wrapper .uct_attr[data-tags="one"]').doMatch();
// the rest that didn't match 'one'
$('.wrapper .uct_attr[data-tags!="one"]').doNotMatch();我认为问题是属性中有multipul标记。
这方面的任何帮助都是很好的。
C
发布于 2011-10-27 10:30:40
很简单:使用member-of-a-whitespace-delimited-list选择器。
var $els = $(".wrapper .uct_attr");
$els.filter("[data-tags~='one']").doMatch();
$els.not("[data-tags~='one']").doNotMatch();发布于 2011-10-27 10:28:55
非选择器
$('.wrapper').find('div').not('.uct_attr[data-tags="one"]').doNotMatch();发布于 2011-10-27 10:32:23
要匹配属性中的单词,请使用此处定义的~=运算符:http://api.jquery.com/attribute-contains-word-selector/
// if match 'one'
$('.wrapper .uct_attr[datatags~="one"]').doMatch();
// the rest that didn't match 'one'
$('.wrapper .uct_attr').not('[datatags~="one"]').doNotMatch();https://stackoverflow.com/questions/7911093
复制相似问题