如何在 jQuery 中隐藏表格行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1049357/
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 10:30:34  来源:igfitidea点击:

How to hide a table row in jQuery?

jquery

提问by ólafur Waage

I have a table such as this

我有一张这样的桌子

<table class="headerTable" id="headerTable">
    <tbody>
        <tr class="hh">
            <td>test1</td>
            <td>18,164</td>
        </tr>
        <tr class="member">
            <td>test3</td>
            <td>24,343</td>
        </tr>
    </tbody>
</table>

I want to hide the rows with class member.

我想隐藏班级成员的行。

I did something like this but it is not working..

我做了这样的事情,但它不起作用..

$("#headerTable tbody tr:member").hide();

回答by ólafur Waage

Try this

尝试这个

$("#headerTable tbody tr.member").hide();

The selectors in jQuery like CSS selectors, so you should be able to use them like that.

jQuery 中的选择器类似于 CSS 选择器,因此您应该能够像这样使用它们。

You can browse the jQuery selector documentation here, it's full of interesting things you can do.

您可以在此处浏览jQuery 选择器文档,它充满了您可以做的有趣的事情。

回答by cgp

To specify a class using CSS use a dot to signify that it's a class, not a colon.The colon is used by jQuery for filters.

要使用 CSS 指定一个类,请使用点来表示它是一个类,而不是冒号。jQuery 使用冒号作为过滤器。

$("tr.member").hide();

Is just fine unless you want to be specific to a table.

除非您想特定于表,否则很好。

回答by tvanfosson

You could also use find.

您也可以使用find.

$('#headerTable').find('.member').hide();

Or if all the rows (elements, actually) with class membershould be hidden:

或者,如果所有带有类的行(实际上是元素)member都应该隐藏:

$('.member').hide();

should work.

应该管用。

回答by Elzo Valugi

$("#headerTable .member").hide();

$("#headerTable .member").hide();