逗号分隔自动完成与jQuery自动完成 [英] comma separated auto complete with jquery auto complete

查看:106
本文介绍了逗号分隔自动完成与jQuery自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过jquery自动完成插件实现自动完成.一个简单的自动完成对我有用.我无法实现以逗号分隔的自动完成功能.

I am trying to implement auto complete via jquery auto complete plugin.A simple auto complete works for me. I am not able to achieve comma separated auto complete .

请帮助我解决我的问题.

Please help me with where I am going wrong.

我的jquery代码:

My jquery code:

$(document).ready(function() {  
$.getJSON('/releases/new.json', function() {      
alert("inside getJson"); 
alert(data1); 
$('#release_tester_tokens').autocomplete({source:names,multiple: true});  
});
});

谢谢, 拉米亚.

推荐答案

查看是否

See if this walk-through helps. It includes the following code which allows the user to enter multiple search terms separated by commas:

$("#<%= txtMultipleName.ClientID %>").autocomplete({
    source: function (request, response) {
        $.getJSON("AutoComplete.ashx", {
            term: extractLast(request.term)
        }, response);
    },
    search: function () {
        // custom minLength
        var term = extractLast(this.value);
        if (term.length < 1) {
            return false;
        }
    },
    focus: function () {
        // prevent value inserted on focus
        return false;
    },
    select: function (event, ui) {
        var terms = split(this.value);
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push(ui.item.value);
        // add placeholder to get the comma-and-space at the end
        terms.push("");
        this.value = terms.join(", ");
        return false;
    }
});
function split(val) {
    return val.split(/,\s*/);
}
function extractLast(term) {
    return split(term).pop();
}

jQuery UI自动完成页面上也有很多信息.

There is also plenty of information on the jQuery UI autocomplete page.

这篇关于逗号分隔自动完成与jQuery自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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