jQuery 属性包含选择器
我有一组 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?
如何对与我的查询匹配的 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();
我认为该属性中有多个标签的问题。
对此的任何帮助都会很棒。
C
I have a set of divs eg:
<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?
How do I perform and action on the ones that match my query and another on the ones that dont? Keeping in mind I one wish to match one of the words in the attribute data-tags
eg:
// if match 'one'
$('.wrapper .uct_attr[data-tags="one"]').doMatch();
// the rest that didn't match 'one'
$('.wrapper .uct_attr[data-tags!="one"]').doNotMatch();
Issue I think is there are multipul tags in that attribute.
Any help on this would be great.
C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
足够简单:使用 member-of-a-whitespace-delimited-list 选择器。
Simple enough: Use the member-of-a-whitespace-delimited-list selector.
不是选择器
not selector
要匹配属性中的单词,请使用 ~= 运算符,如下定义:http:// /api.jquery.com/attribute-contains-word-selector/
To match a word in an attribute, use the ~= operator as defined here: http://api.jquery.com/attribute-contains-word-selector/