我正在尝试在页面中使用两个自动完成,彼此连接。我正在尝试将变量从一个自动完成传递到另一个。我会留下代码,看看是否有人可以帮助我。
JS: $(函数(){
$('#buscador').autocomplete({
minLength: 1,
source: "home/get_cliente",
focus: function(event,ui){
$('#buscador').val(ui.item.label);
return false;
},
select: function(event, ui){
id_cliente = ui.item.value;
$('#id_cliente').val(id_cliente);
return false;
$('#vehiculo').autocomplete({
minLength: 1,
source: "home/get_carro?id_cliente="+id_cliente,
这一行是我不确定的。
focus: function(event,ui){
$('#vehiculo').val(ui.item.label);
return false;
}
}); //Fin autocomplete vehiculo
}
}); //Fin autocomplete buscador
});
答案 0 :(得分:0)
试试这个:
$(function(){
// Declare global var
var id_cliente = "";
$('#buscador').autocomplete({
minLength: 1,
source: "home/get_cliente",
focus: function(event,ui){
$('#buscador').val(ui.item.label);
return false;
},
select: function(event, ui){
id_cliente = ui.item.value;
$('#id_cliente').val(id_cliente);
return false;
$('#vehiculo').autocomplete({
minLength: 1,
source: "home/get_carro?id_cliente="+id_cliente,
focus: function(event,ui){
$('#vehiculo').val(ui.item.label);
return false;
}
}); //Fin autocomplete vehiculo
}
}); //Fin autocomplete buscador
});