我使用 Jquery 自动完成和数组作为源,我想显示标签而不是值,因为我将值存储在不同的变量中,而它不会显示在表单中。但这是他们在文档中所说的:
The label property is displayed in the suggestion menu. The value will be inserted into the input element when a user selects an item.
示例图片
正在搜索:
选择:
代码:
数组:
var searchcustomer_arr = [{label:"ASD CUSTOMER",value:1},
{label:"Customer 2",value:2}]
Javascript:
$("#customer" ).autocomplete({
source: searchcustomer_arr,
minlength: 2
});
最佳答案
试试这个是否有效:-
$("#customer").autocomplete({
source:[
{label:"ASD CUSTOMER",value:1},
{label:"Customer 2",value:2}
],
minLength: 2,
select: function(event, ui) {
event.preventDefault();
$("#customer").val(ui.item.label);
}
});
关于使用数组作为源的 JQuery 自动完成应在选择时显示标签而不是值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25883455/