我有用户输入时必须显示的数组列表。我已经使用了jQuery自动完成插件来实现此目的,但是我必须将搜索文本显示为自动完成列表中的新选项。例如
我看过搜索和打开方法,但我不太了解。基本上,我想在源代码中添加搜索文本,然后再次绑定下拉列表。这是小提琴
$( "#tags" ).autocomplete({
source: aTags,
search:function(){
},
open:function(){
}
});
我不确定这是否是您要查找的,但是在search
事件方法中,可以在初始化插件后使用新值更新数组,并重置source
选项(请参阅本节底部)。
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"],
// store array length:
len = aTags.length,
// cache the element:
tagsElem = $("#tags");
tagsElem.autocomplete({
source : aTags,
search : function( event, ui ) {
// update array (replace/append value at the end of the array) :
aTags[len] = tagsElem.val();
// reset autocomplete source:
tagsElem.autocomplete( "option", "source", aTags);
},
// EDIT:
open: function( event, ui ) {
// append "new" text to the last option:
$('.ui-autocomplete li:last a').append(' <span style="color:red;">new</span>');
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句