Jquery 隐藏表行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2889070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:29:49  来源:igfitidea点击:

Jquery Hide table rows

jquery

提问by tomasz

I am hiding a bunch of textboxes and it works fine, the problem is, the textboxes are in a table, so I also need to hide the corresponding labels. the structure is something like this

我隐藏了一堆文本框,它工作正常,问题是,文本框在一个表格中,所以我还需要隐藏相应的标签。结构是这样的

<tr>
<td>
Label
</td>
<td>
InputFile
</td>
</tr>

in fact its just easier if I hide the rows that have a fileinput , can someone help please

事实上,如果我隐藏具有文件输入的行,它会更容易,有人可以帮忙吗

回答by Derek

this might work for you...

这可能对你有用......

$('.trhideclass1').hide();

 

 

<tr class="trhideclass1">
  <td>Label</td>
  <td>InputFile</td>
</tr>

回答by Josh Stodola

You just need to traverse up the DOM tree to the nearest <tr>like so...

你只需要<tr>像这样遍历 DOM 树到最近的......

$("#ID_OF_ELEMENT").parents("tr").hide();

jQuery API Reference

jQuery API 参考

回答by Daniel Bardi

This should do the trick.

这应该可以解决问题。

$(textInput).closest("tr").hide();

回答by Muflix

html

html

<tr><td><a href="" onclick=hideRow(event)></a></td></tr>

jquery

查询

function hideRow(event){
  $(event.target || event.srcElement).parents('tr').hide();
}

回答by favo

$('inputFile').parent().parent().children('td > label').hide();

$('inputFile').parent().parent().children('td > label').hide();

can help you navigate two levels up ( to TD, to TR ) moving two levels back down ( all TD's in that TR and their LABEL tags ), applying the hide() function there.

可以帮助您向上导航两个级别(到 TD,到 TR),向下移动两个级别(该 TR 中的所有 TD 及其标签标签),在那里应用 hide() 函数。

if you want to stay at the TR level and hide them:

如果你想留在 TR 级别并隐藏它们:

$('inputFile').parent().parent().hide();

$('inputFile').parent().parent().hide();

… is sufficient.

… 足够了。

you can navigate very easily through the elements using the jquery selectors.

您可以使用 jquery 选择器轻松浏览元素。

parent is documented here: http://api.jquery.com/parent/

此处记录了父级:http: //api.jquery.com/parent/

hide is documented here: http://api.jquery.com/hide/

隐藏记录在这里:http: //api.jquery.com/hide/

回答by ICodeForCoffee

If the label is in a table row you can do this to hide the row:

如果标签在表格行中,您可以这样做以隐藏该行:

('.InputFile').parent().Hide()

You can refine your selector as you need and then get the table row that contains that element.

您可以根据需要优化选择器,然后获取包含该元素的表格行。

JQuery Selectors help: http://api.jquery.com/category/selectors/

JQuery 选择器帮助:http: //api.jquery.com/category/selectors/

EDITThis is the correct way to do it.

编辑这是正确的方法。

    ('.InputFile').parents('tr').hide()

回答by Clem

Using parents('tr').hide()works. However if there is an embedded table, all parent trrows will be hidden. In my case, the entire form is hidden since there are many embedded tables.

使用parents('tr').hide()作品。但是,如果有嵌入式表,所有父tr行都将被隐藏。就我而言,整个表单都隐藏了,因为有很多嵌入的表格。

回答by Joe D

I think your best bet if you want both text field and label to hide simultaneously is assign each with a class and hide them like this:

如果您希望同时隐藏文本字段和标签,我认为最好的办法是为每个字段分配一个类并像这样隐藏它们:

jQuery(".labelClass, .inputClass").hide();