且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery自动完成功能开始按字符"@"

更新时间:2023-11-21 17:45:16

我认为最简单的方法是向源代码提供功能.像这样:

I think the easiest way to do this is to provide a function to source. Something like this:

textbox.autocomplete({
    source: function (request, response) {
        var lastWord = request.term.split(/,\s*/).pop();
        if (lastWord.indexOf('@') == -1) {
            return [];
        }
        $.getJSON('YourUrl' + lastWord, {}, function (data) {
            response(values);
        });
    }
});

这仅在最后一部分是自动完成的情况下有效.

This will only work if the last part is the one being autocompleted though.