【发布时间】:2015-07-04 09:07:01
【问题描述】:
我必须在 jquery 自动完成列表中显示搜索到的文本。我有在列表中添加搜索文本的功能,但我必须使用远程数据源来完成。我有一个返回 array 的 URL。
使用静态数组列表fiddle工作演示
我必须为远程数据源添加相同的功能。如何添加搜索文本作为响应。
$(document).ready(function() {
var tagsElem = $("#tags");
tagsElem.autocomplete({
source : "search.php",
search : function( event, ui ){
if(check(response,tagsElem.val()))
response[response.length]=tagsElem.val()
tagsElem.autocomplete( "option", "source", response);
},
open: function( event, ui ) {
if(check(response,tagsElem.val())){
tagsElem.next().find('li:last a').append(' <span style="color:red;">new</span>');
}
}
});
function check(arrayTag,value){
for(i=0;i<len;i++){
if( arrayTag[i]==value)
return false
}
return true
}
});
【问题讨论】:
标签: jquery autocomplete