Jquery-隐藏除第一个之外的所有tr

3 jquery

我想隐藏除第一个之外的所有 tr。然后我希望每个 tr 在有人点击添加链接时出现。

我怎样才能隐藏除第一个之外的所有表格行。

这是我的http://jsfiddle.net/Nx4cD/9/

$( document ).ready(function() {
$(".add").click(function() {
    var
    $this = $(this),
    $row = $this.closest("tr"),
    $rowIndex = $row.index();
    $row.next().show("medium").find("td").eq(0).html($rowIndex+2);
});
$(".delete").click(function() {
    $(this).closest('tr').hide();
});
Run Code Online (Sandbox Code Playgroud)

});

und*_*ned 5

您可以使用.not()方法排除第一个元素:

$('table tbody tr').not(':first').hide();
Run Code Online (Sandbox Code Playgroud)

为了选择下一个隐藏tr元素,您可以使用.nextAll():hidden选择器:

var $row = $this.closest("tr").nextAll(':hidden').first();
Run Code Online (Sandbox Code Playgroud)