驯服 JQuery 对话框小部件
我正在尝试解决 JQuery 对话框小部件的两个问题。
1) 当对话框是模态的时,在某些计算机屏幕上(缩放和分辨率可能不同),对话框会向文档引入滚动条。显然,对话框下方有一个覆盖层,我假设这就是导致滚动条出现的原因。你知道我如何避免这种情况发生吗 i) 在所有分辨率下 ii) 在任何缩放下
2) 对于特定对话框,我想让“Enter”按钮产生默认操作。到目前为止我尝试过的代码如下,但我无法使其工作。需要明确的是,我已经在此处查看了解决方案。而 div 肯定是专注于开放的。但当我按 [Enter] 时,我在 Chrome 中不断收到这些控制台错误。
FOCUS set ... event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.
这是我到目前为止尝试过的代码:
var opts = { modal: true, open: function() { $(this).focus(); }, focus: function(event, ui) { console.log('FOCUS set'); $(this) .keyup(function(e) { var code = (e.keyCode ? e.keyCode : e.which); if (code == 10 || code == 13) alert('Enter key was pressed.'); e.preventDefault(); console.log('key pressed.'); }); }, ... } $('#mydiv').dialog(opts);
I'm having 2 issues with a JQuery dialog widget that I'm trying to solve.
1) When the dialog is modal, on some computer screens (where the zoom & resolution can vary) the dialog introduces scroll bars to the document. There's obviously an overlay just under the dialog box, and I'm assuming that that's what's causing the scrollbars to appear. Do you know how I can avoid that from happening i) at all resolutions and ii) at any zoom
2) For a particular dialog, I want to make the 'Enter' button produce a default action. The code I've tried so far is below, but I can't make it work. To be clear, I've already looked at the solutions here. And the div is certainly focused on opening. But I keep getting these console errors in Chrome, when I press [Enter].
FOCUS set ... event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.
This is the code I've tried so far:
var opts = { modal: true, open: function() { $(this).focus(); }, focus: function(event, ui) { console.log('FOCUS set'); $(this) .keyup(function(e) { var code = (e.keyCode ? e.keyCode : e.which); if (code == 10 || code == 13) alert('Enter key was pressed.'); e.preventDefault(); console.log('key pressed.'); }); }, ... } $('#mydiv').dialog(opts);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是使用 Enter 关闭的解决方案:
http://jsfiddle.net/J9KvV/
JavaScript
HTML
Here is solution for closing using Enter:
http://jsfiddle.net/J9KvV/
JavaScript
HTML