关闭 jquery 对话框后从表中删除行

Removing the rows from a table after closing the jquery dialog

本文关键字:删除行 jquery 对话框 关闭      更新时间:2023-09-26

我有一个jquery对话框,其中有"+"按钮将添加行和"bin"符号将删除行。到目前为止一切看起来都很好,但是当我关闭并重新打开对话框时,它仍然有添加的行,而是应该重置为只有一行带有"+"和"bin"符号。

<table id="table1" style="table-layout: fixed" class="reptable">
    <tr class="firstclass" id="school0">
        <td ><input type="text" id="rollnum" name="rollnum" class="rollClass" maxlength="20"/></td>
        <td ><select id="school" name="school" multiple="multiple" style="width: 95px; size: 50px" size="3" class="schoolClass"></td>
        <td><img src="<c:url value="/images/add_small.png"/>" id="btnAdd1" class="addImg"/></td>
        <td><img src="images/delete_small.png" id="btnDelete1" class="delImg"/></td >
    </tr>
    <tr class="secondclass" id="college0">
        <td ><input type="text" id="rollnum" name="rollnum" class="rollClass" maxlength="20"/></td>
        <td ><select id="college" name="college" multiple="multiple" style="width: 95px; size: 50px" size="3" class="schoolClass"></td>
        <td><img src="<c:url value="/images/add_small.png"/>" id="btnAdd1" class="addImg"/></td>
        <td><img src="images/delete_small.png" id="btnDelete1" class="delImg"/></td >
    </tr>

$('#school-dialog').dialog({
    //autoOpen : true,
    height : 800,
    width : 950,
    modal : true,
    dialogClass : "schools",
    title : 'School and College',
    closeOnEscape : true,
    open : function(event){
        $('#school-dialog').show();
    },
    close : function(event) { 
        $("#school-dialog").dialog("destroy");
    }
});

对此的任何帮助将不胜感激。

给所有的学校class="school",所有的大学都class="college"。然后,您可以使用以下方法删除除第一行之外的所有内容:

close: function(event) {
    $("#table1 tr.school:gt(0), #table1 tr.college:gt(0)").remove();
    $("#school-dialog").dialog("destroy");
}