因为我想在jQuery对话框打开时将元素设置为焦点。 我写了这段代码:
$(".selector").dialog({
title: "dialog",
buttons: [
{ text: "Yes", click: function () { } },
{ text: "No", autofocus: true }
]
});
对于这种情况,这是jsFiddle example。
这似乎在IE9 + / Firefox /等中可行,但在IE8中却没有。 所以我在jquery-ui中找到了_focusTabbable函数。
var hasFocus = this.element.find("[autofocus]");
if ( !hasFocus.length ) {
hasFocus = this.element.find(":tabbable");
}
if (!hasFocus.length) {
hasFocus = this.uiDialogButtonPane.find(":tabbable");
}
这只会在ui-content中找到自动对焦元素,而不是在按钮面板中。 怎么会在uiDialogButtonPane中调用find:tabbable,但是没有应用[autofocus]?
更有趣的是,即使在IE11 / Firefox中,我看到该功能最终聚焦了“是”按钮,但恰好弹出了一个焦点为“否”按钮的对话框。找不到理由。