在日常开发中,我们经常会用到自定义属性,那么jQuery如何选择自定义属性为指定内容的元素呢?
示例HTML代码:
<ul>
<li class="dd-item" data-nav-url="/a/getting-started/installation.html">
<a href="/a/getting-started/installation.html">
<i class="fa fa-check read-icon"></i>
<span><b></b>安装</span>
</a>
</li>
<li class="dd-item" data-nav-url="/a/getting-started/basic-usage.html">
<a href="/a/getting-started/basic-usage.html">
<i class="fa fa-check read-icon"></i>
<span><b></b>基本用法</span>
</a>
</li>
<li class="dd-item" data-nav-url="/a/getting-started/builds-and-modules.html">
<a href="/a/getting-started/builds-and-modules.html">
<i class="fa fa-check read-icon"></i>
<span><b></b>版本和模块</span>
</a>
</li>
</ul>
如果我们想获取data-nav-url值为/a/getting-started/basic-usage.html的li,jQuery代码如下:
var l = jQuery("li[data-nav-id='/a/getting-started/basic-usage.html']");