我有一个 jQuery UI 对话框,其中包含许多按钮。
我想对这些按钮进行键盘控制(选项卡导航),因此在对话框的打开事件处理程序上,我将第一个按钮设置为焦点。
我可以明显地看到这个工作,并且还使用 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>
如您所见,我一直尝试添加事件处理程序,但没有任何反应!