11

次のハイパーリンクの挿入テキスト入力に何かを入力すると、すべての単語がtextareaその後ろに表示されます。OK ボタンとキャンセル ボタンは正常に機能しますが、テキスト入力に集中できません。

jQuery UI 1.10.1 を使用しています。1.8.x であった以前のバージョンの jQuery で問題なく動作していました。

ここに画像の説明を入力

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

4

5 に答える 5

10

私が見つけた2番目の答えは、次のコードで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();
                        }
                    });
                }
            });
        }
于 2013-03-28T15:27:47.070 に答える
1

この問題を解決するために私がしたことは、これをコメントアウトすることです$(".ui-dialog:visible:last .ui-dialog-content").data("ui-dialog")._focusTabbable();

完全なコードは次のとおりです。

    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();
                    }
                });
            }
        });
    }
于 2013-03-27T17:56:19.783 に答える
1

jquery ダイアログからのフォーカスのブロックを停止する別の方法

$.widget("ui.dialog", $.ui.dialog, {
    _allowInteraction: function (event) {
        return !!$(event.target).closest(".input-container").length || this._super(event);
    }
});

.input-containerフォーカスを受け取る必要があるコントロールを含むコンテナーはどこにありますか。

于 2019-08-02T14:40:50.467 に答える