jQuery-Autocomplete - 选择项目时显示下拉列表

问题描述 投票:0回答:1

我正在使用jQuery-自动完成。它工作正常,当字段为空时,它会显示焦点上的下拉菜单,但当已选择某个项目时,它不会显示它。我希望它打开,无论输入字段中是否有任何内容 - 当字段处于焦点时。这不起作用:'$('#my-input').trigger("focus");'。我该怎么做?

这是我的相关代码片段:

$('#my-input').autocomplete({
        lookup: some_array,
        minChars: 0
    });
javascript jquery jquery-ui-autocomplete
1个回答
0
投票

尝试使用

onFocus
选项强制显示下拉菜单。这是一个例子 -->

   $('#my-input').autocomplete({
        lookup: some_array,
        minChars: 0,
        showNoSuggestionNotice: true,
        noSuggestionNotice: 'No results',
        onSelect: function (suggestion) {
            //Add your onSelect code here
        },
        onFocus: function () {
            $(this).autocomplete('search', $(this).val());
        }
    });
    
    $('#my-input').focus(function() {
        $(this).autocomplete('search', $(this).val());
    });
© www.soinside.com 2019 - 2024. All rights reserved.