jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery UI焦点窃取大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
每当我在下面的插入超链接文本输入中键入内容时,所有单词都将转到后面的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);
},

取自这里:http://code.jquery.com/ui/1.10.1/jquery-ui.js

解决方法

第二个答案我发现在下面的代码中jQuery将文档绑定到对话框.因此,当我点击所需按钮的onclick事件(或您正在处理的任何事件)时解除绑定:
if (window.jQuery && window.jQuery.ui.dialog) {
   $(document).unbind("focusin.dialog");
 }

这是jQuery UI将_focusTabble()方法绑定到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焦点窃取全部内容,希望文章能够帮你解决jQuery UI焦点窃取所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: