jQuery autocomplete 1.1:集中显示所有数据 [英] jQuery autocomplete 1.1: Show All Data on focus

查看:84
本文介绍了jQuery autocomplete 1.1:集中显示所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使此扩展名集中显示所有数据?我试图将minChars更改为 0 ,但是它仅在双击输入时显示.

How to make this extension show all data on focus?. I have tried to change minChars to 0 but it only show when the input double clicked.

$("#month").autocomplete(months, {
        minChars: 0,
        max: 12,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 220,
        formatItem: function(data, i, total) {
            // don't show the current month in the list of values (for whatever reason)
            if ( data[0] == months[new Date().getMonth()] ) 
                return false;
            return data[0];
        }
    });

推荐答案

您需要将焦点事件绑定到输入并作为结果调用jQuery UI方法.以此js小提琴为例

You need to bind a focus event to the input and call the jQuery UI method as a result. Take a look at this js fiddle for an example

我添加了以下代码:

$('#month').autocomplete({
    // Your current code
}).on('focus', function(event) {
    var self = this;
    $(self).autocomplete( "search", this.value);;
});

传递给 search 方法的值是自动完成功能要查找的内容.

the value passed into the search method is what the autocomplete will look for.

如何重点搜索所有值

如果您希望所有可用的下拉菜单都将其保留为",而是将 minLength:0 添加到options对象.

If you want all available dropdowns leave it as "" but add minLength : 0 to the options object.

$('#month').autocomplete({
    minLength : 0
}).on('focus', function(event) {
    $(this).autocomplete("search", "");
});

这篇关于jQuery autocomplete 1.1:集中显示所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆