Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery查找具有值的表格单元格并突出显示tr_Jquery_Css - Fatal编程技术网

jquery查找具有值的表格单元格并突出显示tr

jquery查找具有值的表格单元格并突出显示tr,jquery,css,Jquery,Css,我所做的: $('#transport td').filter(function() { return $(this).text() == 'TPS999'; }).addClass("marked"); 现在是重点 如何突出显示找到文本(tr)的行?使用最近('tr')获取父行并返回行,而不是td $('#transport td').filter(function() { if($(this).text() == 'TPS999') return $(this

我所做的:

$('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
}).addClass("marked");
现在是重点

如何突出显示找到文本(tr)的行?

使用
最近('tr')
获取父
并返回行,而不是
td

$('#transport td').filter(function() {
    if($(this).text() == 'TPS999')
       return $(this).closest('tr');
}).addClass("marked");
或者,您可以使用选择包含指定文本的所有元素,并使用
closest('tr')
获取父级
td
,并向其添加类

$('#transport td:contains("TPS999")').closest('tr').addClass("marked");
试试这个:

$('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
}).closest('tr').addClass("marked");
像这样:

var $cell = $('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
});

$cell.closest('tr').addClass("marked")

代码

$('#transport td').filter(
function(t){
     if($(this).text() =="TPS999") {
        $(this).closest('tr').css('background-color','Red');
        // alert("i am in");
        return;
    }

});