Javascript jquery删除表行

Javascript jquery删除表行,javascript,jquery,animation,Javascript,Jquery,Animation,我在删除表格行时遇到问题,我可以突出显示红色的行,但当我尝试删除它时,slideup函数会出错。我把它们包在一个div中,但我不知道如何访问tr的子对象,然后访问tr的子对象 $('#test tr:not(:first)').click(function() { $(this).css("background-color","red"); $(this).children("td div").slide

我在删除表格行时遇到问题,我可以突出显示红色的行,但当我尝试删除它时,slideup函数会出错。我把它们包在一个div中,但我不知道如何访问tr的子对象,然后访问tr的子对象

$('#test tr:not(:first)').click(function()
        {           
            $(this).css("background-color","red");  

            $(this).children("td div").slideUp(function()
            {    
                $(this).parent().remove(); 
            });              
        });
问题在于这一行:

$(this).children("td div").slideUp(function()
我也试过了

$(this).children("td").children("div").slideUp(function()
向上滑动仅删除第一列

<table border="1" width="600" cellspacing="0" cellpadding="0" id="test">
    <tr>
        <td><b>First Name</b></td>
        <td><b>Last Name</b></td>
        <td><b>Address</b></td>
        <td><b>Town</b></td>

    </tr>

    <tr>
        <td><div>First Name</td>
        <td>Last Name</td>
        <td>Address</td>
        <td>Town</div></td>

    </tr>

</table>

名字
姓
住址
镇
名字
姓
住址
镇
我是否需要用
div
标签包装每个
的内容

谢谢

调用
子项(“td div”)
将找到与选择器匹配的所有直接子项。(恰好位于
s内部的
s的所有子项)
由于所有直接子级都是
s,因此它将不匹配任何内容

调用
children(“td”)。children(“div”)
将在所有
s中找到所有
s。
因此,它将找到您仅有的

编辑:可以使用jQuery创建包装器元素;:

$('testtr:not(:first')。单击(function(){
$(this.css(“背景色”、“红色”);
$(this).children().wrapInner(“”).children().slideUp(function(){
$(this).closest('tr').remove();
});
});

调用
子项(“td div”)
将找到与选择器匹配的所有直接子项。(恰好位于
s内部的
s的所有子项)
由于所有直接子级都是
s,因此它将不匹配任何内容

调用
children(“td”)。children(“div”)
将在所有
s中找到所有
s。
因此,它将找到您仅有的

编辑:可以使用jQuery创建包装器元素;:

$('testtr:not(:first')。单击(function(){
$(this.css(“背景色”、“红色”);
$(this).children().wrapInner(“”).children().slideUp(function(){
$(this).closest('tr').remove();
});
});

谢谢,我现在明白了,我对孩子们有些困惑。是否有一种更简单的方法不必为每个TD使用div?它每一个都有一个div…但有点“哈奇”。@Elliot:是的。然而,jQuery可以为您做到这一点@Elliott:实际上应该调用
wrapInner
,而不是
contents();否则,如果
元素中有多个子元素(我编辑以显示这一点),它将无法正常工作。对不起,谢谢,我现在明白了,我对孩子们有点困惑。是否有一种更简单的方法不必为每个TD使用div?它每一个都有一个div…但有点“哈奇”。@Elliot:是的。然而,jQuery可以为您做到这一点@Elliott:实际上应该调用
wrapInner
,而不是
contents();否则,如果
元素中有多个子元素(我编辑以显示这一点),它将无法正常工作。很抱歉
$('#test tr:not(:first)').click(function() {           
    $(this).css("background-color","red");  

    $(this).children().wrapInner('<div>').children().slideUp(function() {    
        $(this).closest('tr').remove();
    });
});