我有张表格,有个删除按钮,点击删除按钮,就删除数据库一条信息,表格就应该少一行。
我是这样做的,我点击input按钮,就获得了一行的主键,然后用jquery的ajax方法传到后台页面,删除后,弹出成功按钮。
现在问题是,删除后,怎么让表格少一行,而不需要刷新后才少一行。

解决方案 »

  1.   

    要删除的话,把记录的主键和每行的tr的id关联,确认删除成功后,移除该tr<table style="width: 98%; background-color: #e7e3e7;" cellspacing="1" cellpadding="4"
        align="center" id="ajaxtable">
        <tbody>
            <tr align="center" class="head">
                <td style="width: 5%;">
                    操作
                </td>
                <td width="50%">
                    文件名
                </td>
                <td style="width: 30%;">
                    生成日期
                </td>
            </tr>
            <% for (int i = 0; i < files.Count; i++) { %>
            <%FileInfo f = files[i]; %>
            <tr id="tr_<%=i %>" align="center" class="dinfo" style="background-color: #D8D8D8;">
                <td>
                    <a href="javascript:delF('<%=f.Name %>','delfile',<%=ModelID %>,<%=i %>)">删除</a>
                </td>
                <td>
                    <a href="/<%=FilePath + "/" + ModelID + "/" + f.Name %>" target="_blank">
                        <%=f.Name %>
                    </a>
                </td>
                <td>
                    <%=f.LastWriteTime.ToString("yyyy-MM-dd HH:mm") %>
                </td>
            </tr>
            <%} %>
        </tbody>
    </table>function delF(id, act, modelid,idx) {
        if (confirm("确定要删除此文件?")) {
            $.post("/handler/CommonHandler.ashx", { action: act, fid: id, mid: modelid }, function(data) {
                if (data == "1") {
                    Boxy.alert("删除成功", refreshP, { title: "结果", closeText: '' });
                    if (act == "delfile") {
                        $("#tr_" + idx).remove();
                    }
                } else if (data == "0") {
                    Boxy.alert("系统忙,请稍候再试", null, { title: "操作失败" }); ;
                } else if (data == "-1") {
                    Boxy.alert("您还没有登录,请先登录", null, { title: "请登录" });
                } else if (data == "-2") {
                    Boxy.alert("参数错误!", null, { title: "参数非法" });
                }
                else if (data == "-3") {
                    Boxy.alert("模板文件对应任务,不能删除!", null, { title: "失败" });
                }
                else if (data == "-4") {
                    Boxy.alert("文件不存在!", null, { title: "失败" });
                }
            });
        }
    }
      

  2.   

    最好是 重新绑定 Table