Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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 基于相邻单元格中的值有条件地隐藏表中的单元格_Jquery_Html_Formatting - Fatal编程技术网

Jquery 基于相邻单元格中的值有条件地隐藏表中的单元格

Jquery 基于相邻单元格中的值有条件地隐藏表中的单元格,jquery,html,formatting,Jquery,Html,Formatting,我使用第三方网格显示一些数据,但我无法控制它生成的标记 在下面的示例中,我想隐藏相邻单元格没有值的行(即下面示例中的中间行)的提交按钮 我认为这在jQuery中是可能的,但是我有点拘泥于如何有条件地做事情 <div id="grid"> <table> <tr> <td>123</td><td><a href="/go/somewhere">Submit</a

我使用第三方网格显示一些数据,但我无法控制它生成的标记

在下面的示例中,我想隐藏相邻单元格没有值的行(即下面示例中的中间行)的提交按钮

我认为这在jQuery中是可能的,但是我有点拘泥于如何有条件地做事情

<div id="grid">
    <table>
        <tr>
            <td>123</td><td><a href="/go/somewhere">Submit</a></td>
        </tr>
        <tr>
            <td></td><td><a href="/go/somewhere">Submit</a></td>
        </tr>
        <tr>
            <td>123</td><td><a href="/go/somewhere">Submit</a></td>
        </tr>
    </table>
<div>

123
123

有什么想法吗?

我想这应该行得通,我已经试过了,它按预期工作

var cells = $("table tr td:first-child");

cells.each(function(i){
    if ($(this).text() === ''){
         $(this).next().find('a').hide();
    }
});

我想这应该行得通,我已经试过了,它的效果和预期的一样

var cells = $("table tr td:first-child");

cells.each(function(i){
    if ($(this).text() === ''){
         $(this).next().find('a').hide();
    }
});

您可以使用
.filter()
jQuery方法,在其中插入您自己的逻辑

$('a').filter(function () {
    return $(this).closest('tr').find('td:first-child').html() === '';
}).hide();
在末尾链接一个简单的
.hide()


Edit,改为td:first child,可以加快速度。

您可以使用
.filter()
jQuery方法,在其中插入您自己的逻辑

$('a').filter(function () {
    return $(this).closest('tr').find('td:first-child').html() === '';
}).hide();
在末尾链接一个简单的
.hide()

编辑,改为td:first child,加快速度。

演示:

演示: