当用户点击/选择自动完成项目时,我很难确定插入的位置以及如何进行点击功能。然后我想用点击的项目进行数据库查询。
我当前的自动填充脚本:
$("#search_customer").autocomplete({
source: "search.php",
minLength: 1,
response: function(event, ui) {
if (!ui.content.length) {
var create_customer = alert('bla bla...');
if (create_customer)
{
console.log('yes');
}
else
{
console.log('no');
}
}
}
});
答案 0 :(得分:0)
使用jquery ui自动完成的select
回调
e.g
$("#search_customer").autocomplete({
source: "search.php",
minLength: 1,
select: function(event,ui) {
var label = ui.item.label; // label of selected item
var value = ui.item.value; // value of selected item
// then make an ajax call here to get the data from db.
},
response: function(event, ui) {
if (!ui.content.length) {
var create_customer = alert('bla bla...');
if (create_customer)
{
console.log('yes');
}
else
{
console.log('no');
}
}
}
});
希望这有帮助。