jquery UI dialog 缓存问题解决

来源:互联网 发布:团伙研发作弊软件 编辑:程序博客网 时间:2024/05/29 15:16

dialog如果复用一个div,第二次弹出有可能会出现第一次弹出框的属性,解决方法(见红字部分):



function roleUpdate(roleIdentity, role) {
//解决dialog中的缓存问题
var dialogParent = $("#addDialog").parent();
var dialogOwn = $("#addDialog").clone();
dialogOwn.hide();


    $("#roleIdentity").val(roleIdentity);
    $("#roleIdentity").attr("disabled", "disabled");


    if (role == "ROLE_ADMIN") {  //比较值
        $("#radioRoleAdmin").attr("checked", "checked");
    }
    else {
        $("#radioRoleOrdinary").attr("checked", "checked");
    }


    $("#addDialog").dialog({
        resizable: false,
        height: 300,
        width: 400,
        title: "修改role",
        modal: true,
        open: function () {//去掉默认的关闭按钮
              $(".ui-dialog-titlebar-close", $(this).parent()).hide();
        },
        close: function() {//解决dialog中的缓存问题
        dialogOwn.appendTo(dialogParent);
        $(this).dialog("destroy").remove();
        }, 
        buttons: {
            "保存": function () {


                var newRole = $('#addDialog').find('input[name="radioRole"]:checked').val();
                var currentPage = $("#currentPage").val();


                if (roleIdentity == "" || role == "") {
                    alert("用户标识、角色编码不能为空");
                    return;
                }


                var url = "roleUpdate.json?roleIdentity=" + roleIdentity + "&&newRole=" + newRole + "&&currentPage=" + currentPage;
                $.ajax({
                    url: url,// 跳转到 action
                    success: function (data) {
                        $("#addDialog").dialog("close");
                        if (data.status) {
                            alert("修改成功");
                            location.reload();
                        }
                        else {
                            alert("修改失败。");
                        }


                    },
                    error: function () {
                        alert("异常!");
                    }
                });


            },
            "取消": function () {
                $("#addDialog").dialog("close");
            }
        }
    });
}

原创粉丝点击