我有下面的函数,它将一个 URL 加载到我的对话框中,当打开该 URL 时,一个函数在准备好的文档上运行,该函数根据一个值显示或隐藏 div。反过来扩展对话框,自动高度工作,但对话框向下扩展并且不再居中。
所以对话框打开>在对话框中打开URL>显示面板运行>对话框扩展高度>对话框不再居中。
代码尝试自动重新中心
$.ui.dialog.prototype.options.autoReposition = true;
$(window).resize(function () {
$(".editDialog").dialog("option", "position", "center");
$(".ui-dialog-content:visible").each(function () {
$(this).dialog("option", "position", $(this).dialog("option", "position"));
});
});
$(".ui-dialog-content").resize(function () {
$(".ui-dialog-content:visible").each(function () {
$(this).dialog("option", "position", $(this).dialog("option", "position"));
});
});
对话代码
$(document).ready(function () {
var width = $(window).width() / 2;
$.ajaxSetup({ cache: false });
$(".editDialog").live("click", function (e) {
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Edit',
autoOpen: false,
resizable: true,
autoResize:true,
minHeight: 'auto',
width: width,
modal: true,
draggable: true,
open: function (event, ui) {
//Show the loading div on open.
$("#dvLoading").show();
//adding a callback function wich will be launched after the loading
$(this).load(url,function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$(this).html(msg + xhr.status + " " + xhr.statusText);
} else $("#dvLoading").hide();
});
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-edit").dialog('open');
return false;
});
URL 文档就绪 显示/隐藏 DIVS
$(document).ready(function () {
showPanel()
});
function showPanel()
{
var panel = $("#lstAssetTypes").val();
panel = panel.substr(panel.indexOf(",") + 1)
switch (panel)
{
case "User":
$("#dvWKS").show();
$("#dvNTW").hide();
break;
case "Network":
$("#dvWKS").hide();
$("#dvNTW").show();
break;
default:
break;
}
}
用于 Div 的 HTML 称为
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure to delete?
</p>
</div>
<div id="dialog-edit" style="display: none">
<div id="dvLoading" class="loading"><img src="~/Images/loading.gif"><p>Loading please wait...</p></div>
</div>
<div id="dialog-view" style="display: none">
</div>