我创建了一个 jQuery 对话框。下面是我创建的 Ajax 函数。
$.ajax({
url: "/StaffManageCertifications/GetExamCodesAndCategory/",
type: "Post",
datatype: "html",
success: function (data) {
debugger;
$('#divExamCodesCategory').html(data);
$("#divExamCodesCategory").dialog({
autoOpen: false,
width: 700,
height: 610,
modal: true,
resizable: false,
draggable: true,
title: 'Add Exam Code/Category'
});
$("#divExamCodesCategory").dialog("open");
$('a.ui-dialog-titlebar-close').remove();
$('#divProcessImage').css({
"display": "none"
});
},
error: function (req, status, error) {
ErrorMessageStaff(req.responseText);
$('#screen').css({
"display": "block",
"width": "",
"height": ""
});
$('#divProcessImage').css({
"display": "none"
});
}
});
现在,我在该 div = divExamCodesCategory 上放置了两个按钮(确定和取消)。
并在下面编写代码行,以便每次关闭此对话框时都会销毁该对话框。
$("#divExamCodesCategory").dialog("destroy");
现在,当我第二次打开它时, 第一次单击 - 它不显示对话框。 第二次单击时 - 它确实显示对话框,但没有数据。空对话框。
此外,它也没有出现在屏幕中央。它下降到屏幕底部。下面是该对话框的位置样式。
.ui-dialog {
padding: 0em !important;
position: fixed !important;
}
对此的任何帮助表示赞赏。
谢谢。
最佳答案
如果您打算在每次关闭对话框时销毁对话框,则需要在对话框的关闭处理程序中完成:
$(...).dialog({
...,
close: function() {
$(this).dialog('destroy');
}
});
就目前情况而言,如果您的(未显示的)destroy
调用紧随您所描述的 AJAX 调用之后,那么它实际上会立即发生,因为 AJAX 调用是异步的 并立即完成。
附:不要使用 $.css({'display': 'none'})
,只需使用 .hide()
关于jQuery:对话框第二次无法正确打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17609147/