我有一个 jQuery 自动完成字段,到目前为止一直运行良好。我决定在其上使用 _renderItem
因为我想在结果中使用一些 HTML。这是我的代码:
function prepareClientField() {
var renderItemFunction = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append(item.label)
.appendTo(ul);
};
$("#client_name").autocomplete({
source: clientNames,
delay: 0
}).data("autocomplete")._renderItem = renderItemFunction;
$("#client_name").focus();
}
出于某种原因,现在我无法在自动完成字段中使用向上/向下箭头。我什至无法使用鼠标单击结果中的项目。我还需要做些什么才能使其真正发挥作用吗?
最佳答案
autocomplete
插件严重依赖于 menu
插件,后者在内部使用 a
元素。因此,从每个项目中删除 a
元素会破坏 menu
插件。
您可以手动安装 menu
插件并尝试让它工作,或者您需要找到另一个解决方案,其中项目具有 a
标签,但是不要搞乱你的风格。
关于jquery - 使用 _renderItem 类型会破坏自动完成字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086952/