0
$('table.listings td:contains("You")').each(function(){
 $(this).children('td:nth-child(2)').addClass('highlighted');
});

table.listings在页面上有多个,但包含“你”的那个被选中,我想将类添加highlighted到每一行的第二个单元格,但上面的代码没有按我预期的那样工作。

4

3 回答 3

0

试试这个:

$('table.listings td:contains("You")').each(function(){
    $("td:nth-child(2)", $(this).parent().parent().get(0)).addClass('highlighted');
});
于 2010-02-08T04:50:46.993 回答
0
$('table.listings :contains("You")').each(function(){
 $(this).children('td:nth-child(2)').addClass('highlighted');
});
于 2010-02-08T04:53:00.047 回答
0
$('table.listings:contains("You") td:nth-child(2)').addClass("highlight");
于 2010-02-08T05:13:25.170 回答