驯服 JQuery 对话框小部件

发布于 2024-12-21 20:53:57 字数 1103 浏览 2 评论 0原文

我正在尝试解决 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖风昔人 2024-12-28 20:53:57

以下是使用 Enter 关闭的解决方案:

http://jsfiddle.net/J9KvV/

JavaScript

$(document).ready(function () {
    $('#dialog').dialog();
    $(document).keydown(function (event) {
        var dialog = $('#dialog');
        if (dialog.dialog('isOpen')) {
            if (event.keyCode === 13) {
                dialog.dialog('close');
            }
        }
    });
});

HTML

<div id="dialog" title="Header">
My Window
</div>

Here is solution for closing using Enter:

http://jsfiddle.net/J9KvV/

JavaScript

$(document).ready(function () {
    $('#dialog').dialog();
    $(document).keydown(function (event) {
        var dialog = $('#dialog');
        if (dialog.dialog('isOpen')) {
            if (event.keyCode === 13) {
                dialog.dialog('close');
            }
        }
    });
});

HTML

<div id="dialog" title="Header">
My Window
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文