1
有没有基于数据属性检索元素的方法?根据数据属性检索html元素
我有下面的代码,并想知道如何才能实现这一目标
<UL>
<LI data-relation_id=1/>
<LI data-relation_id=1/>
<LI data-relation_id=1/>
<LI data-relation_id=2/>
<LI data-relation_id=2/>
<LI data-relation_id=2/>
<LI data-relation_id=3/>
<LI data-relation_id=3/>
<LI data-relation_id=3/>
</UL>
上的click事件我基本上要找出属于一个特定的数据关系的所有项目?
function getRelatedObjects(relationId){
//Search all the li's and get the LI
//that have the data-relation_id== relationId
}
这可以使用jQuery来完成吗?