【发布时间】:2013-03-27 17:33:45
【问题描述】:
每当我在下面的“插入超链接”文本输入中键入内容时,所有单词都会在其后面指向textarea。确定和取消按钮工作正常,但我无法专注于文本输入。
我们使用的是 jQuery UI 1.10.1。它与以前版本的 jQuery 1.8.x 配合得很好。
我检查了 jQuery 背后的代码,它在打开模态对话框时调用了以下方法:
_focusTabbable: function () {
// Set focus to the first match:
// 1. First element inside the dialog matching [autofocus]
// 2. Tabbable element inside the content element
// 3. Tabbable element inside the buttonpane
// 4. The close button
// 5. The dialog itself
var hasFocus = this.element.find("[autofocus]");
if (!hasFocus.length) {
hasFocus = this.element.find(":tabbable");
}
if (!hasFocus.length) {
hasFocus = this.uiDialogButtonPane.find(":tabbable");
}
if (!hasFocus.length) {
hasFocus = this.uiDialogTitlebarClose.filter(":tabbable");
}
if (!hasFocus.length) {
hasFocus = this.uiDialog;
}
hasFocus.eq(0).focus();
},
_keepFocus: function (event) {
function checkFocus() {
var activeElement = this.document[0].activeElement,
isActive = this.uiDialog[0] === activeElement ||
$.contains(this.uiDialog[0], activeElement);
if (!isActive) {
this._focusTabbable();
}
}
event.preventDefault();
checkFocus.call(this);
// support: IE
// IE <= 8 doesn't prevent moving focus even with event.preventDefault()
// so we check again later
this._delay(checkFocus);
},
【问题讨论】:
-
有趣...我在带有垂直内容滚动条的对话框中遇到了类似的锚标签问题。如果我向下滚动并单击对话框中的任意位置,焦点将滚动回对话框中最顶部的锚标记。我已将其追溯到您引用的代码,但我不喜欢注释掉该代码......我也不应该......而且我觉得解除绑定很脏。
-
这是 jQuery UI 中的一个错误:bugs.jqueryui.com/ticket/9101。应该会在下个版本修复。
-
该错误已在 jQuery UI 1.11.0 中修复。那是我正在运行的版本,但我仍然观察到这个问题。
标签: jquery jquery-ui modal-dialog