<ul>
<li id="RadListBox1_i2" class="rlbItem ui-draggable">
<div class="ui-draggable ui-state-default" data-shortid="1007">
<em>ProductId: </em>
<span>110-01-070-10</span>
<br>
<em>ShortID: </em>
<span class="ShortID" data-shortid="1007">1007</span>
<br>
<em>Product Defaul cat: </em>
<span class="spanDefCat" data-defcat="334">334</span>
</div>
</span>
</li>
<li id="RadListBox1_i3" class="rlbItem ui-draggable">
<li id="RadListBox1_i4" class="rlbItem ui-draggable">
</ul>
我需要找到这个元素,我之前正在使用此功能
$("#AllProducts li:contains('ShortID:" + Product + "'):contains('" + iCategory + "')").addClass("backDefaultCat");
但是现在您看到我正在使用data-shortid = X播种,所以我需要检查项目是否具有data-shortid = X和data-defcat = Y
有些人这样想
$("span.ShortID[data-shortid=" + Product + "] span.spanDefCat[data-defcat=" + iCategory + "]").parents("li:first").addClass("backDefaultCat");
我可以将其正确组合。
尝试
$("#AllProducts li").filter(function(){
return $(this).has('[data-shortid="' + Product + '"]').length > 0 && $(this).has('[data-defcat="' + iCategory + '"]').length > 0
}).addClass("backDefaultCat");
演示:小提琴
或者
$('#AllProducts li:has(span.ShortID[data-shortid="' + Product + '"]):has(span.spanDefCat[data-defcat="' + iCategory + '"])').addClass("backDefaultCat");
演示:小提琴
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句