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來完成嗎?