-1

我有这个 ol 列表

<ol><li class="first"><a href="/ivory/node/183">Sour Candy Spray 8.5ml (3 flavors)</a></li>
<li><a href="/ivory/node/181">Chap Ice Mini Stick 3g (Cherry)</a></li>
<li><a href="/ivory/node/180">Chap Ice Mini Stick 3g (Kiwi)</a></li>
<li><a href="/ivory/node/179">Chap Ice Mini Stick 3g (Orange)</a></li>
<li><a class="active" href="/ivory/node/166">Chap Ice Beeswax</a></li>
<li><a href="/ivory/node/165">Chap Ice Cherry Stick</a></li>
<li><a href="/ivory/node/170">Chap Ice Crazy Flavors 4.2g (Blueraspberry)</a></li>
<li><a href="/ivory/node/169">Chap Ice Crazy Flavors 4.2g (Watermelon)</a></li>
<li><a href="/ivory/node/168">Chap Ice Crazy Flavors Verry Berry 4.2g</a></li>
<li><a href="/ivory/node/167">Chap Ice Moisture 4.2g Stick</a></li>
<li><a href="/ivory/node/164">Chap Ice Original 4.2g Stick</a></li>
<li class="last"><a href="/ivory/node/163">ChapIce 10G Petrolium Jelly Squeeze Tube</a></li>
</ol>

如何找到包含“Chap Ice Cherry Stick”的li,并给它一个唯一的ID?

4

1 回答 1

2

尝试这个,

$('li a:contains("Chap Ice Cherry Stick")').parent().attr('id', youruniqueID)

如果您期望出现多个元素

$('li a:contains("Chap Ice Cherry Stick")').each(function(index, elem){
   $(this).parent().attr('id', "chap" + index);
})
于 2012-12-23T01:39:17.537 回答