Jquery ui jQueryUI对话框窃取焦点

Jquery ui jQueryUI对话框窃取焦点,jquery-ui,client-side,Jquery Ui,Client Side,我有一个jQueryUI对话框,其中有许多按钮 我希望在这些按钮上有键盘控制(选项卡导航),因此在对话框的open event handler上,我将第一个按钮设置为focused 我可以清楚地看到这是可行的,并且还可以使用document.activeElement验证它,但是焦点随后被窃取,其他东西获得了焦点 到这个时候,我不知道我应该如何看到什么有焦点,因为我没有任何进一步的钩子 还有其他人注意到类似的问题吗 如果您感兴趣,我的代码如下(修改为添加焦点,如下所述) 在doc.ready中—

我有一个jQueryUI对话框,其中有许多按钮

我希望在这些按钮上有键盘控制(选项卡导航),因此在对话框的open event handler上,我将第一个按钮设置为focused

我可以清楚地看到这是可行的,并且还可以使用document.activeElement验证它,但是焦点随后被窃取,其他东西获得了焦点

到这个时候,我不知道我应该如何看到什么有焦点,因为我没有任何进一步的钩子

还有其他人注意到类似的问题吗

如果您感兴趣,我的代码如下(修改为添加焦点,如下所述)

在doc.ready中——注意,我还添加了jQuery按钮——但它们似乎根本不响应键盘事件——但这是一个单独的问题

        $("#dialogSearchType").dialog
        (
            {
                bgiframe: true,
                height: 180,
                width: 350,
                modal: true,
                autoOpen: false,
                show: 'drop',
                hide: 'fold',
                buttons: { "Street": function() { HandleSearchStreetClick(); $(this).dialog("close"); },
                    "Property": function() { HandleSearchPropertyClick(); $(this).dialog("close"); }
                },
                focus: function(event, ui) { $("#btnSearchTypeProperty").focus(); }
            }
        );


    <div id="dialogSearchType" class="searchDialog" style="width: 280px; display: none" title="Search For..." onkeyup="HandleSearchTypeDialogKeyUp(event)">
        <span>What would you like to search for?</span>
        <br />                
                     <input type="button" tabindex="1" id="btnSearchTypeStreet" class="button" value="Street" onclick="HandleDialogSearchStreetClick()" />
        <input type="button" tabindex="2" id="btnSearchTypeProperty" class="button" value="Property" />           

    </div>
$(“#dialogSearchType”).dialog
(
{
bgiframe:是的,
身高:180,
宽度:350,
莫代尔:是的,
自动打开:错误,
表演:'放下',
隐藏:“折叠”,
按钮:{“Street”:函数(){HandleSearchStreetClick();$(this).dialog(“close”);},
“属性”:函数(){HandleSearchPropertyClick();$(this).dialog(“close”);}
},
焦点:函数(事件,ui){$(“#btnSearchTypeProperty”).focus();}
}
);
您想搜索什么?


正如您所看到的,我已经尝试了添加事件处理程序,但是什么都没有发生

尝试使用而不是打开事件处理程序,看看这是否有帮助。我认为这可能更正确,因为除非对话框是模态的,否则您可能希望默认按钮在每次对话框获得焦点时都获得焦点,而不仅仅是在对话框打开时。如果这不起作用,那么我建议您在问题中添加代码。

好的,我知道问题出在哪里了

        $("#dialogSearchType").dialog
        (
            {
                bgiframe: true,
                height: 180,
                width: 350,
                modal: true,
                autoOpen: false,
                show: 'drop',
                hide: 'fold',
                buttons: { "Street": function() { HandleSearchStreetClick(); $(this).dialog("close"); },
                    "Property": function() { HandleSearchPropertyClick(); $(this).dialog("close"); }
                },
                focus: function(event, ui) { $("#btnSearchTypeProperty").focus(); }
            }
        );


    <div id="dialogSearchType" class="searchDialog" style="width: 280px; display: none" title="Search For..." onkeyup="HandleSearchTypeDialogKeyUp(event)">
        <span>What would you like to search for?</span>
        <br />                
                     <input type="button" tabindex="1" id="btnSearchTypeStreet" class="button" value="Street" onclick="HandleDialogSearchStreetClick()" />
        <input type="button" tabindex="2" id="btnSearchTypeProperty" class="button" value="Property" />           

    </div>
对话框设置为模态

jQuery将在文档级别截取键盘事件,并取消它们

我认为这很糟糕,所以我正在尝试一种解决方法来销毁这个事件处理程序并添加我自己的事件处理程序


PS如果有人知道怎么做,让我知道

在这里,您可以找到一个对我们有用的有趣解决方案


谢谢,遗憾的是,这不起作用-我已经编辑了我的Q并添加了代码片段。我的另一个大问题(我想我会作为一个单独的问题来回答)是内置按钮(使用按钮选项)根本不接受键盘输入。我可以看到jQuery UI在显示时将焦点设置为其中一个,但唯一有效的键盘事件是关闭对话框的ESC!:(