按键时关闭 ModalWindow
我希望能够在用户按下某个键(在我的例子中是 ESC)时关闭 ModalWindow。
我有一个用于按键的 Javascript 侦听器,它调用取消按钮 ID 的单击事件:
jQuery("#"+modalWindowInfo.closeButtonId).click();
这是正确的方法吗?
我想知道它在 Chrome 中工作但在 FF 中不起作用,但这可能是由于我的具体实现所致。
I would like to be able to close a ModalWindow when the user presses a key, in my case ESC.
I have a Javascript listener for the keypress which calls the click event of the cancel button's ID:
jQuery("#"+modalWindowInfo.closeButtonId).click();
Is this the correct way to do it?
I am wondering because it works in Chrome but not in FF, but it could be due my specific implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“正确”的方法是调用服务器,然后用响应关闭它。您可以使用 ajax 行为来做到这一点:
ModalTestPage.java
ModalTestPage.html
The 'right' way to do it is to call the server, then close it with the response. You can do this with an ajax behavior:
ModalTestPage.java
ModalTestPage.html
上面的例子很好,非常好,但是有一个问题对于某些编程用户(对我来说)可能至关重要。
为了实现实际的关闭,会发生 2 个 ajax 请求 - 第一个请求是通过调用
window.close
的CloseOnESCBehavior
发出的。 MW.close() 将呈现 JavaScript,该 JavaScript 首先调用服务器来询问其windowClosedCallback
,并且只会然后关闭(隐藏其内容)模式窗口。我建议改为在 ModalWindow ctor 的代码中执行类似的操作:
The example above is good, very good, however there is one issue which may be crucial for some programming users (was for me).
For the actual close to happen there are 2 ajax requests happening - first one is issued with the
CloseOnESCBehavior
which callswindow.close
. MW.close() would render javascript which would first do call to server to ask itswindowClosedCallback
, and would only then close (hide contents of) the modal window.I'd suggest instead doing something like this - in the code of ModalWindow ctor:
另外,您可以使用 Wicket Jquery UI
HTML
Java
并且 ESC 键可以正常工作。您应该在 Wicket JQuery UI 演示页面
Also, you can use Wicket Jquery UI
HTML
Java
And the ESC key works fine. You should see this aproach at Wicket JQuery UI demo page