单个ESC关闭jQuery UI中的所有模态对话框。解决方法? [英] Single ESC closes ALL modal dialogs in jQuery UI. Workarounds?

查看:165
本文介绍了单个ESC关闭jQuery UI中的所有模态对话框。解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,jQuery中还存在一个错误: http://bugs.jqueryui.com / ticket / 4511



此行为的原因(从错误描述注释):对话框本身将keydown事件绑定到自身以关闭对话框在 ESC 上;另外,对话框覆盖将keydown事件绑定到文档,而不进行过滤以仅关闭活动对话框。



I不能想出一个可接受的解决方法的想法。有没有人必须处理它?<​​/ p>

解决方案

非常简单 - 创建一个模态对话框,运行这个: / p>

  $([document,window])。unbind('。dialog-overlay'); 

如果您创建了多个模态对话框,点击 ESC 将关闭只有一个。
然后一旦你专注于底部对话框,点击 ESC ,它也会关闭它。



希望这有帮助! / p>

PS jQuery UI开发人员应该添加一个选项,当您希望所有对话框一次关闭时,按 ESC 键或仅关注焦点。


Actually, there was (is still) a bug in jQuery: http://bugs.jqueryui.com/ticket/4511.

The reason for this behavior (from the bug description comments): "The dialog itself binds keydown event to itself for closing the dialog on ESC; in addition, the dialog overlay binds a keydown event to the document, without filtering to close only the active dialog."

I cannot come up with an idea of an acceptable workaround. Is there anyone who has had to deal with it yet?

解决方案

Very simple - upon creating a modal dialog, run this:

$([document, window]).unbind('.dialog-overlay'); 

If you create more then one modal dialog, hitting ESC will close the top one only. Then once you focus on the bottom dialog, hit ESC and it will close it as well.

Hope this helped!

P.S. jQuery UI developers should add an option when you want all dialogs close at once upon hitting ESC key or only the focused ones.

这篇关于单个ESC关闭jQuery UI中的所有模态对话框。解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆