我的场景:
单击 Dialog1 中的特定元素时,将打开 Dialog2。
当您按 Escape 关闭 Dialog2 时,按预期工作并关闭 Dialog2。
Dialog1 仍然存在,您会认为可以通过再次点击 Escape 来关闭它,但事实并非如此。您必须先单击对话框,然后单击 Escape 以将其关闭。
这是我尝试过的,但无济于事:
// Array to hold all of our open dialogs id's
var openDialogs = [];
// the open: method in my dialog
open: function() {
openDialogs[openDialogs.length] = $(this).attr("id");
}
// the close: method in my dialog
close: function() {
var index = $.inArray($(this).attr("id"), openDialogs),
$previousDialog = (index > 0) ? $("#" + openDialogs[index]) : undefined;
// remove the current dialog from the array via Jon Resig's remove() method
openDialogs.remove(index);
// set focus to previously opened dialog
if ($previousDialog) { $previousDialog.focus(); }
// I've even tried:
//
// if ($previousDialog) { $previousDialog.dialog("moveToTop"); }
}