jQuery UI 对话框 closeOnEscape 不适用于多个打开的对话框
我的场景:
当单击 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"); }
}
My scenario:
When a particular element in Dialog1 is clicked, Dialog2 opens.
When you hit Escape to close Dialog2, works as expected and closes Dialog2.
Dialog1 remains and you would think that it could be closed by hitting Escape again, but it doesn't. You have to first click on the dialog and then hit Escape for it to close.
Here's what I have tried, but to no avail:
// 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"); }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一行:
将使
$previousDialog
引用当前对话框(正在关闭的对话框)。index
是正在关闭的对话框的索引。因此,稍后在这一行:
在关闭的对话框上调用
focus()
。我相信你想要的是这样的:
这是一个工作示例: http://jsfiddle.net/L8J7Y/
我还注意到,如果您使用
$previousDialog.dialog("widget").focus();
相反,您可以避免在对话框周围出现可能令人讨厌的虚线。This line:
Will make
$previousDialog
refer to the current dialog (the one being closed).index
is the index of the dialog that is being closed.Therefore, later on this line:
Is calling
focus()
on the dialog that was closed.I believe what you want is something like this:
Here's a working example: http://jsfiddle.net/L8J7Y/
I also noticed that if you use
$previousDialog.dialog("widget").focus();
instead, you avoid getting the possibly annoying dotted line around the dialog.在关闭函数中如何将其放入,
因为所有对话框都具有该类,因此它将关闭所有对话框
how about in the close function you put this
as all dialogs have that class so it will close all dialogs