gpt4 book ai didi

jQuery UI 焦点窃取

转载 作者:行者123 更新时间:2023-12-03 22:21:57 24 4
gpt4 key购买 nike

每当我在下面的“插入超链接”文本输入中键入内容时,所有单词都会出现在其后面的 textarea 中。 “确定”和“取消”按钮工作正常,但我无法专注于文本输入。

我们正在使用 jQuery UI 1.10.1。它与之前版本的 jQuery 1.8.x 配合得很好。

enter image description here

我检查了 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);
},

取自此处:http://code.jquery.com/ui/1.10.1/jquery-ui.js

最佳答案

我发现的第二个答案是,在下面的代码中,jQuery 将文档绑定(bind)到对话框。因此,当我单击所需按钮的 onclick 事件(或您正在处理的任何事件)时解除绑定(bind)时:

 if (window.jQuery && window.jQuery.ui.dialog) {
$(document).unbind("focusin.dialog");
}

这是 jQuery UI 将 _focusTabble() 方法绑定(bind)到文档的 focusin.dialog 事件的地方。

if ( !$.ui.dialog.overlayInstances ) {
// Prevent use of anchors and inputs.
// We use a delay in case the overlay is created from an
// event that we're going to be cancelling. (#2804)
this._delay(function() {
// Handle .dialog().dialog("close") (#4065)
if ( $.ui.dialog.overlayInstances ) {
this.document.bind( "focusin.dialog", function( event ) {
if ( !$( event.target ).closest(".ui-dialog").length &&
// TODO: Remove hack when datepicker implements
// the .ui-front logic (#8989)
!$( event.target ).closest(".ui-datepicker").length ) {
event.preventDefault();
$(".ui-dialog:visible:last .ui-dialog-content")
.data("ui-dialog")._focusTabbable();
}
});
}
});
}

关于jQuery UI 焦点窃取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15665552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com