Jquery CSS选择器:选择TR,其中TD包含特殊值

Jquery CSS选择器:选择TR,其中TD包含特殊值,jquery,css,selector,Jquery,Css,Selector,我有一张这样的桌子: <table> <tr> <td> row4545 </td> </tr> <tr> <td> row22 </td> </tr> <tr> <td> r

我有一张这样的桌子:

<table>
    <tr>
        <td>
            row4545
        </td>
    </tr>
    <tr>
        <td>
            row22
        </td>
    </tr>
    <tr>
        <td>
            row6767
        </td>
    </tr>
</table>
我想在tr上设置一个背景色,其中包含td中的值row22。 是否可以使用CSS以某种方式选择它

PS:我使用jQuery

$('td').filter(function(){
     return $.trim($(this).text()) === "row22";
}).closest('tr').css('color','red');
演示-->

试试看

$('tr td').filter(function(){
    return $.trim($(this).text()) === "row22";
}).parent().css('background-color', 'blue')
演示:

这应该会有帮助

$('tr td').filter(function() {
    return $(this).text() == "row22";
}).parent().css('background-color','red');
您可以尝试以下方法:

$(function(){
    $("td:contains('row22')").filter(function(){        
        $.trim($(this).text()) == 'row22' ? $(this).parent().attr('style','background:red;') : '';
    });
});
你可以这样写:

$(document).ready(function() {
    $( "td:contains(row22)").css("background-color","red");
});

包含或等于第22行?jQuery与之有什么关系?你想用CSS还是jQuery/JavaScript来选择它?我不相信只有用CSS才有可能……内容是固定的还是动态的?如果它是固定的,那么只需在这些元素上添加一个类
$(document).ready(function() {
    $( "td:contains(row22)").css("background-color","red");
});