Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个 html 代码:
<p class="test" data-id=1>Some Value</p> <p class="test" data-id=2>Some Value</p> <p class="test" data-id=3>Some Value</p> <p class="test" data-id=4>Some Value</p>
如何<p>根据元素选择元素data-id?
<p>
data-id
使用 jQuery:
alert($("p[data-id='1']").html());
演示
jQuery - 属性选择器