关闭 DOMWindow() [JQuery] 后.focus() 不起作用

发布于 2024-09-29 01:26:40 字数 1551 浏览 0 评论 0原文

我有一系列 DIV 元素,单击这些元素时会触发 DOMWindow 打开事件。那里没问题。

然后我必须添加键盘辅助功能。哦!!

我向 DIV 添加了 tabindex 属性,这允许用户从一个 DIV 切换到下一个 DIV,并且我添加了一个按键处理程序来处理 Enter 键。那里没问题。

我遇到的问题是尝试将焦点设置回用户按下 Enter 键并打开 DOMWindow 时所在的 div(以便他们可以继续切换到该系列中的下一个 DIV)。

我尝试将一个函数添加到 DOMWindow 的“functionCallOnClose”设置中,但这似乎没有执行任何操作。

这是一个代码片段。这将单击和按键事件绑定到类名为“timeEntry”的所有 DIV:

$(".timeEntry").live("click keypress", function () {

    // bunch of code here to set up the DOMWindow...

    $.openDOMWindow({

        // bunch of settings here...

        functionCallOnClose: function () {
            // this doesn't work
            // 'DivId' is the object (DIV) that was clicked on
            $(DivId).focus();
        }
    });

});

有人知道为什么在单击或按键事件被触发后我似乎无法将焦点返回到原始 DIV 吗?处理?

我意识到这是一个相当晦涩的问题,所以我把它扔在那里,希望其他人阅读这篇文章时使用 JQuery、DOMWindow,并处理单击和按键事件(或者至少知道如何处理)

:o)

编辑:经过一些进一步的调试,似乎 jQuery 从 DIV 标签获取 tabIndex 属性存在问题。当我查看页面的源代码时,我可以看到属性:

<div id="someDiv" class="someClass" tabindex="1"> ... </div>

但是,当我尝试使用 jQuery 获取属性时,它似乎不存在。

这段代码返回“未定义”

var tabindex = $("#someDiv").attr("tabindex");

但是,如果我使用 jQuery 设置属性,我可以转身并检索它:

// set the tabindex
$("#someDiv").attr("tabindex", "1");

// now this returns "1"
var tabindex = $("#someDiv").attr("tabindex");

有谁知道为什么 jQuery 在 HTML 中设置 tabindex 属性时不返回 tabindex 属性,但之后会返回它是使用代码动态设置的吗?

希望这是有道理的......

I have a series of DIV elements that, when clicked on, trigger a DOMWindow open event. No problem there.

Then I had to add keyboard accessibility. DOH!!

I added tabindex attributes to the DIVs, which allows the user to tab from one DIV to the next, and I added a keypress handler to deal with the Enter Key. No problem there.

The problem I AM experiencing is trying to set the focus back to the div that the user was on when he or she hit the Enter Key and opened the DOMWindow (so they can continue tabbing to the next DIV in the series).

I tried adding a function to the "functionCallOnClose" setting of the DOMWindow, but that doesn't appear to do anything.

Here is a code snippet. This is binding the click and keypress events to all DIVs that have a class name of "timeEntry":

$(".timeEntry").live("click keypress", function () {

    // bunch of code here to set up the DOMWindow...

    $.openDOMWindow({

        // bunch of settings here...

        functionCallOnClose: function () {
            // this doesn't work
            // 'DivId' is the object (DIV) that was clicked on
            $(DivId).focus();
        }
    });

});

Does anyone have a clue why I can't seem to get the focus back to the original DIV after the click or keypress events are fired and handled?

I realize this is a pretty obscure question, so I'm throwing it out there in hopes that someone else reading this is using JQuery, DOMWindow, and handling click and keypress events (or at least knows how)

:o)

EDIT: After doing some further debugging, it seems that there is a problem with jQuery getting the tabIndex attribute from DIV tags. When I view the source of my page, I can see the attributes:

<div id="someDiv" class="someClass" tabindex="1"> ... </div>

However, when I try to get the attribute using jQuery, it does not appear to be there.

This code returns "undefined"

var tabindex = $("#someDiv").attr("tabindex");

However, if I set the attribute using jQuery, I can turn around and retrieve it:

// set the tabindex
$("#someDiv").attr("tabindex", "1");

// now this returns "1"
var tabindex = $("#someDiv").attr("tabindex");

Does anyone have a clue why jQuery doesn't return the tabindex attribute when it is set in the HTML, but it will after it is set dynamically using code?

Hope this makes sense...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

星星的軌跡 2024-10-06 01:26:40

这个问题听起来很有趣,所以我做了一些搜索,发现了这个: http://api.jquery.com /attr/#comment-92512642

这可能是 jquery 版本 1.4.3 中的一个错误(根据链接在 1.4.2 中工作)。

the problem sound interesting so I did some search and found this: http://api.jquery.com/attr/#comment-92512642

It may be a bug in jquery version 1.4.3 (works in 1.4.2 according to link).

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