我想隐藏除第一个之外的所有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();
});
});
答案 0 :(得分:4)
您可以使用.not()
方法排除第一个元素:
$('table tbody tr').not(':first').hide();
要选择下一个隐藏的tr
元素,您可以使用.nextAll()
和:hidden
选择器:
var $row = $this.closest("tr").nextAll(':hidden').first();
答案 1 :(得分:0)
尝试使用JQuery index here:
$(".delete").click(function() {
var parentRow = $(this).closest('.table > tbody > tr');
if(parentRow.index() != 0){
parentRow.hide();
}
});