jQuery自动完成功能开始按字符"@" [英] jquery autocomplete to start on pressing character '@'
本文介绍了jQuery自动完成功能开始按字符"@"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本区域,可以在其中编写消息.我想为某些条件激活jquery自动完成功能 -当用户按"@"时,他们应该开始看到建议,直到不按空格为止.
I have a textarea in which I write messages. I want to activate jquery autocomplete for certain condition like - when user presses '@', they should start seeing the suggestion till they dont press space.
这类似于Facebook风格的@friends预测.
It is something similar to facebook style @friends prediction.
jquery本质上支持此吗? 有什么想法吗?
Does jquery inherently support this? Any ideas?
推荐答案
我认为最简单的方法是向源代码提供功能.像这样:
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.
这篇关于jQuery自动完成功能开始按字符"@"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文