使用jQuery UI自动完成设置隐藏输入值后
$( "#PName" ).autocomplete({
search: function(event, ui) {
$("#PLoading").show();
},
source: "Script_URL",
minLength: 2,
select: function( event, ui ) {
$("#PLoading").hide();
$("#PName").val(ui.item.value);
$("#PID").val(ui.item.id);
}
});
<input type="hidden" id="PID" name="PID" value="0" />
用于通过自动完成功能将隐藏输入的新值发送到其他网址,发送0值
0值是隐藏输入默认值,(对于测试,我将默认值更改为90,但再次发送默认值(90))
$("#CName").autocomplete({
search: function(event, ui) {
$("#CLoading").show();
alert ($("#PID").val()); // it's worked, and alert new value , from hidden input
},
source: "Script_URL/"+$("#PID").val(), /// but it's not worked , does not send new value from hidden input
minLength: 2,
select: function( event, ui ) {
$("#CLoading").hide();
$( "#CName" ).val(ui.item.value);
$( "#CID" ).val(ui.item.id);
}
});
答案 0 :(得分:2)
当窗口小部件初始化时,您的代码只会读取隐藏输入的值一次。如果您想每次都更新源URL,则必须为source
参数提供一个函数并自行发出AJAX请求:
$( "#PName" ).autocomplete({
search: function(event, ui) {
$("#PLoading").show();
},
source: function () {
$.ajax({
url: "Script_URL/" + $("#PID").val(),
data: request,
dataType: "json",
success: function (data) {
response(data);
},
error: function () {
response([]);
}
});
},
minLength: 2,
select: function( event, ui ) {
$("#PLoading").hide();
$("#PName").val(ui.item.value);
$("#PID").val(ui.item.id);
}
});