【问题标题】:Autocomplete: How to focus on first item after pressing arrow down key on last item?自动完成:在最后一项上按下箭头键后如何关注第一项?
【发布时间】:2016-11-18 07:41:01
【问题描述】:

使用向下箭头键浏览下拉菜单的每个选项。当关注最后一个选项并按下箭头键时,光标将移动到文本框而不是第一个选项。如何使光标转到第一个选项?

【问题讨论】:

    标签: javascript jquery css jquery-ui autocomplete


    【解决方案1】:

    您可以使用下面的代码块来解决该问题。

    .autocomplete('instance')._move = function( direction, event ) {
        if ( !this.menu.element.is( ":visible" ) ) {
            this.search( null, event );
            return;
        }
        if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
             this.menu.isLastItem() && /^next/.test( direction ) ) {
            if ( !this.isMultiLine ) {
                this._value( this.term );
            }
            this.menu[ direction ]( event );
            // this.menu.blur();
            return;
        }
        this.menu[ direction ]( event );
    }
    

    【讨论】:

    • 感谢您的帮助!太有用了:)
    猜你喜欢
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多