使用HTML5的自定义数据属性的jQuery选择器 [英] jQuery selectors on custom data attributes using HTML5
本文介绍了使用HTML5的自定义数据属性的jQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道哪些选择器可用于HTML5附带的这些数据属性。
I would like to know what selectors are available for these data attributes that come with HTML5.
以这段HTML为例:
<ul data-group="Companies">
<li data-company="Microsoft"></li>
<li data-company="Google"></li>
<li data-company ="Facebook"></li>
</ul>
是否有选择器:
- 所有元素
data-company =Microsoft
低于公司
- 所有元素
data-company!=Microsoft
低于公司
- 在其他情况下,可以使用其他选择器,例如包含,小于,大于等......。
- All elements with
data-company="Microsoft"
below"Companies"
- All elements with
data-company!="Microsoft"
below"Companies"
- In other cases is it possible to use other selectors like "contains, less than, greater than, etc...".
推荐答案
$("ul[data-group='Companies'] li[data-company='Microsoft']") //Get all elements with data-company="Microsoft" below "Companies"
$("ul[data-group='Companies'] li:not([data-company='Microsoft'])") //get all elements with data-company!="Microsoft" below "Companies"
查看 jQuery选择器:包含选择器
这里有关于的信息:包含选择器
这篇关于使用HTML5的自定义数据属性的jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文