我在我的Web项目中使用jQuery自动完成插件。我想显示3个元素,然后在底部添加“查看所有结果”链接。
我尝试了以下代码。
$( ".grid-search-box" ).autocomplete({
minLength: 0,
source: temp,
focus: function( event, ui ) {
$( ".grid-search-box" ).val( ui.item.value );
return false;
},
select: function( event, ui ) {
$( ".grid-search-box" ).val( ui.item.value );
return false;
}
}).data( "autocomplete" )._renderItem = function( ul, item )
{
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a><span class='" + item.status + "'></span>" + item.value + "</a>" )
.appendTo( ul );
};
谁能建议我,如何解决。
最佳答案
这是演示,
http://jsfiddle.net/muthkum/vqwBP/105/
我希望您能弄清楚如何实现。
更新:
我设法更新了您的代码,
$( ".grid-search-box" ).autocomplete({
minLength: 0,
source: function(request, response) {
var results = $.ui.autocomplete.filter(temp, request.term);
response(results.slice(0, 3)); //show 3 items.
},
open: function(event, ui) {
$('.ui-autocomplete').append('<li><a href="javascript:alert(\'redirecting...\')">See All Result</a></li>'); //See all results
},
focus: function( event, ui ) {
$( ".grid-search-box" ).val( ui.item.value );
return false;
},
select: function( event, ui ) {
$( ".grid-search-box" ).val( ui.item.value );
return false;
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a><span class='" + item.status + "'></span>" + item.value + "</a>" )
.appendTo( ul );
};
演示:http://jsfiddle.net/muthkum/vqwBP/106/
关于jQuery自动完成附加链接在底部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12479498/