删除表行不工作

Remove table row doesn't work

本文关键字:工作 删除      更新时间:2023-09-26

我试图从一个表格里面删除一个表行(tr)。我用这个函数来做。

$('.removeStop').click(function() {
    $(this).closest('tr').fadeTo(400, 0, function () { 
        $(this).remove();
    });
    return false;
});

fadeTo工作得很好,但是当它要删除行时,它会去到remove函数,它会进入一个无限循环"cannot remove undefined"

也许这只是我犯的一些愚蠢的错误,但我想如果它可以淡出整个行,它应该能够删除相同的东西

任何帮助都将是伟大的:)

编辑:这里是HTML:

<tr align="left">
                <td width="100">School: </td>
                <td>
                    <select name="stops[school][0][studentid]" class="combobox" style="display: none; ">
                    <option value="">Select a school...</option>
                    <option value="1" selected="selected">Hogwarts School of Wizardry</option><option value="2">Itchy and Scratchy Land</option><option value="3">Springfield Elementary</option>                       </select><input class="ui-autocomplete-input ui-widget ui-widget-content ui-corner-left ui-corner-right inputCustom" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
                </td>
                <td width="70"></td>
                <td width="100">Time (24hr): </td>
                                    <td><input class="ui-widget ui-widget-content ui-corner-left ui-corner-right inputCustom" value="15" name="stops[school][0][hr]" style="width:50px;" type="text"> <input class="ui-widget ui-widget-content ui-corner-left ui-corner-right inputCustom" value="01" name="stops[school][0][min]" style="width:50px;" type="text"></td>
                <td><a href="#" class="removeStop">Remove</a></td>
            </tr>

试试这个:

$('.removeStop').click(function(e) {
    e.preventDefault();
    $(this).closest('tr').fadeOut(400, function () { 
        $(this).remove();
    });
});