-1

我有一个这样的表:

<table>
    <tr>
        <td>
            row4545
        </td>
    </tr>
    <tr>
        <td>
            row22
        </td>
    </tr>
    <tr>
        <td>
            row6767
        </td>
    </tr>
</table>

我想在 tr 上设置背景颜色,其中包含 td 中的值 row22。是否可以使用 CSS 以某种方式选择它?

PS:我使用 jQuery。

4

6 回答 6

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

演示---> http://jsfiddle.net/jJWs2/2/

于 2013-06-19T10:29:03.600 回答
2

尝试

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

演示:小提琴

于 2013-06-19T10:30:05.010 回答
1

你可以这样写:

$(document).ready(function() {
    $( "td:contains(row22)").css("background-color","red");
});
于 2014-06-04T15:51:51.657 回答
0

你可以试试这个:

$(function(){
    $("td:contains('row22')").filter(function(){        
        $.trim($(this).text()) == 'row22' ? $(this).parent().attr('style','background:red;') : '';
    });
});
于 2013-06-19T10:33:42.057 回答
0

这应该有帮助..

$('tr td').filter(function() {
    return $(this).text() == "row22";
}).parent().css('background-color','red');
于 2013-06-19T10:30:53.533 回答
-1
<table>
    <tr style="background:#000;">
        <td>
            row4545
        </td>
    </tr>
    <tr>
        <td>
            row22
        </td>
    </tr>
    <tr>
        <td>
            row6767
        </td>
    </tr>
</table>
于 2013-06-19T10:30:21.777 回答