我在使用Jquery UI模态对话框时遇到了问题。我有一个模态对话框(dialogA),它可以创建另一个模态对话框(dialogB)。在第二次创建并关闭dialogB后,dialogA的覆盖层消失了。
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><link type="text/css" rel="Stylesheet" href="ui-lightness/jquery-ui-1.8.custom.css" />
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript">
function createDialog(dialogId) {
$('#' + dialogId).dialog({
autoOpen: true,
modal: true,
buttons: {
'close': function() {
$(this).dialog('close');
},
'create': function() {
var newDialogId = dialogId + '1';
$('body').append('<div id="' + newDialogId + '">' + newDialogId + '</div>');
createDialog(newDialogId);
}
},
close: function() {
$(this).dialog('destroy');
$(this).remove();
}
});
}
$(document).ready(function() {
$('#button1').click(function() {
var dialogId = 'dialog';
$('body').append('<div id="' + dialogId + '">' + dialogId + '</div>');
createDialog(dialogId);
});
});
</script>
</head>
<body>
<button id="button1">Create dialog</button>
</body>
</html>
重现步骤:
1. 点击按钮创建对话框(dialog)
2. 在第一个对话框内点击“创建”按钮,创建另一个对话框(dialogA)
3. 关闭 dialogA
4. 重复步骤 2-3
5. 第一个对话框的覆盖层已消失
谢谢