使用HTML5的自定义数据属性的jQuery选择器

妖精的绣舞 提交于 2020-10-05 06:38:21

问题:

I would like to know what selectors are available for these data attributes that come with HTML5. 我想知道哪些选择器可用于HTML5附带的这些数据属性。

Taking this piece of HTML as an example: 以这段HTML为例:

<ul data-group="Companies">
  <li data-company="Microsoft"></li>
  <li data-company="Google"></li>
  <li data-company ="Facebook"></li>
</ul>

Are there selectors to get: 是否有选择器:

  • All elements with data-company="Microsoft" below "Companies" 所有带有data-company="Microsoft"元素都在"Companies"之下
  • All elements with data-company!="Microsoft" below "Companies" 所有带有data-company!="Microsoft"元素都在"Companies"之下
  • In other cases is it possible to use other selectors like "contains, less than, greater than, etc...". 在其他情况下,可以使用其他选择器,如“包含,小于,大于等......”。

解决方案:

参考一: https://stackoom.com/question/HOh4/使用HTML-的自定义数据属性的jQuery选择器
参考二: https://oldbug.net/q/HOh4/jQuery-selectors-on-custom-data-attributes-using-HTML5
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!