【发布时间】:2011-06-15 14:21:43
【问题描述】:
我需要一次显示 2 个对话框模式。由于第一个对话框的内容需要使用一些绝对定位和 z-indexing,所以叠加层的 z-index 对我来说很重要。
我遇到的问题是,如果我在 z-index 为 300 处显示第一个模态,则叠加层的 z-index 为 301。如果我随后显示另一个 z-index 为 500 的模态,则新的叠加层会得到z-index 为 501。如果我关闭两个模态并再次打开第一个模态,而不是获得 z-index 为 301 的叠加层,它是 503。
这是一些示例代码。
<html>
<head>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#modal').hide();
$('#success-message').hide();
$('#show-modal-button').click(function(){
$('#modal').dialog({
modal: true,
buttons: {
OK: function () {
$(this).dialog("close");
}
},
draggable: false,
title: 'test modal',
resizable: false,
zIndex: 400
});
});
$('#modal-button').click(function(){
$('#success-message').dialog({
modal: true,
buttons: {
OK: function () {
$(this).dialog("close");
}
},
draggable: false,
title: 'test modal',
resizable: false,
zIndex: 500
});
});
});
</script>
</head>
<body>
<input type="button" id="show-modal-button" value="show modal"/>
<div id="modal">
<input type="button" id="modal-button" value="push"/>
</div>
<div id="success-message"><p>test</p></div>
</body>
</html>
更新 使用下面的代码关闭时,我可以通过从 DOM 中删除小部件来使其工作。我觉得这是一个 hack,它要么是一个错误,要么是我在我的方法中做错了什么。如果没有人能告诉我我做错了什么,我会发布我的解决方案作为答案。
$('#modal-button').click(function(){
$('#success-message').dialog({
modal: true,
buttons: {
OK: function () {
$(this).dialog("close");
$(this).dialog('widget').remove();
}
},
draggable: false,
title: 'test modal',
resizable: false,
zIndex: 500
});
});
【问题讨论】:
标签: jquery-ui dialog z-index modal-dialog