我正在尝试使用jquery自动完成和自定义html在我的下拉列表中添加图像。由于某些原因,当我设置图像时,当我输入名称时,自动完成功能看起来很好(我看到的图片和标签都很好),但是当我向下箭头选择时,我得到一个错误,说ui.item没有为焦点和选择事件定义。如果我遵循示例页面中所示标准格式,则一切工作正常。
( jquery文档中的那个--按照预期工作)
.append( "<a>" + item.label + "<br>" + item.value + "</a>" ) 但是当我使用这个来显示图像时,自动完成列表显示了图片,但是焦点和选择事件不起作用
$( "#friends" ).autocomplete({
minLength: 2,
source: friend_data,
delay: 0,
autofocus: true,
focus: function(event, ui) {
$( "#friends" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#friends" ).val( ui.item.label );
return false;
}
})
.data( "autocomplete")._renderItem = function( ul, item ) {
var fb_pic_path = '<img src="http://graph.facebook.com/' + item.value + '/picture?type=square">' ;
console.log(fb_pic_path);
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( fb_pic_path + item.label )
.appendTo( ul );
};发布于 2012-06-03 17:33:42
啊.。我想通了。需要锚点。
.append( "<a>" + fb_pic_path + item.label + "</a>" )现在它运行得很好。
https://stackoverflow.com/questions/10868978
复制相似问题