【问题标题】:Auto Select Single Match jQuery UI Autocomplete Combobox自动选择单匹配 jQuery UI 自动完成组合框
【发布时间】:2014-09-01 16:37:52
【问题描述】:

我正在使用一个稍微流行的 Combobox UI 元素,它是一个自定义 jQuery UI 自动完成扩展:see here

我想,如果有一个匹配项可以选择该匹配项并触发选定的事件,那么具体更改自动完成组合框中的这部分代码应该是解决方案:

    _source: function (request, response) {
                var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
                response(this.element.children("option").map(function () {
                    var text = $(this).text();
                    var value = $(this).val();
                    if (this.value && (!request.term || matcher.test(text)))
                        return {
                            label: text,
                            value: value,
                            option: this
                        };
                }));
            }

我不熟悉 jQuery map 函数,虽然我对 jQuery 和 vanilla Javascript 非常熟悉,但它的语法对我来说并不熟悉,尽管我了解该函数的作用。

我想要类似的东西:

if(match.count == 1)
   //fire select event and/or select option in hidden select list

【问题讨论】:

    标签: javascript jquery jquery-ui combobox autocomplete


    【解决方案1】:
    var data = [
      "Apple",
      "Orange",
      "Pineapple",
      "Strawberry",
      "Mango"
    ];
    
    $(document).ready(function () {
        $( "#fruits" ).autocomplete({
            source: data,
            autoFocus: true,
        });
    });
    

    【讨论】:

    • 您可以在 HTML 中使用如下代码
    • 主要道具先生或妈妈,急需的答案!衷心的感谢。
    猜你喜欢
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 2011-04-07
    • 2011-11-16
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多