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