【发布时间】:2017-05-03 05:06:57
【问题描述】:
当我的 jQuery 对话框从前一个 jQuery 对话框中弹出时,我发现它的高度存在问题。在下面的示例中,第一个对话框正确显示为 200 宽 x 200 高。单击“确定”按钮应关闭第一个对话框并打开 400 宽 x 400 高的第二个对话框,但它没有:第二个对话框显示为 200 宽 x 400 高。
我最初在使用 jQuery 1.11.2 时发现了这个问题,但它也在 3.2.1 中重现。
该示例在我的环境中工作,但我是 jsfiddle 新手,无法在这里工作。
有人可以告诉我我做错了什么或提供解决方法吗?谢谢。
$(document).ready(function() {
$("#testBox").dialog({
dialogClass: "customDialog",
autoOpen: false,
draggable: false,
modal: true,
show: {
effect: "blind",
duration: 100
},
hide: {
effect: "blind",
duration: 100
}
});
});
function openTestDialog() {
$('#testBox').html('<p>first pop</p>');
$('#testBox').dialog("option", "title", "Title of the dialog");
$('#testBox').dialog("option", "width", 200);
$('#testBox').dialog("option", "height", 200);
$('#testBox').dialog("option", "modal", true);
$('#testBox').dialog({
buttons: [{
text: "Pop 2nd",
click: function() {
$(this).dialog("close");
pop2();
}
}]
});
$('#testBox').dialog("open");
}
function pop2() {
$('#testBox').html('<p>second pop</p>');
$('#testBox').dialog("option", "title", "Title of the second dialog");
$('#testBox').dialog("option", "width", 400);
$('#testBox').dialog("option", "height", 400);
$('#testBox').dialog("option", "modal", true);
$('#testBox').dialog({
buttons: [{
text: "OK",
click: function() {
$(this).dialog("close");
}
}]
});
$('#testBox').dialog("open");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<div id="testBox"></div>
<button type="button" onclick="openTestDialog();">First pop</button>
【问题讨论】:
-
是高度还是宽度的问题?
-
实际上,我在这两个方面都遇到过问题,但不是同时发生的。
-
我不确定发生了什么,但是当我检查 DOM 元素时,它有
height: auto而不是代码设置的高度。我不知道为什么。 -
也许你应该在 forums.jquery.com 上询问这个问题,或者提交一个错误报告。