问候,
我正在使用官方的Autocomplete jquery小部件,并且我正在通过查询字符串动态更改变量(selectType)。变量将根据通过选择框选择的选项而改变。
$(function() {
var selectType = $('#selectType option:selected').attr("value");
$("#selectType").change(function(){
selectType = $('#selectType option:selected').attr("value");
alert (selectType); // alerts the right value for debugging
});
$("#address").autocomplete({
source: "ajaxSearchForClientAddress.php?selectType="+selectType,
minLength: 3
});
});
答案 0 :(得分:75)
尝试在更改事件中实际更改自动填充的source
选项。
$(function () {
var select = $( "#selectType" ),
options = select.find( "option" ),
address = $( "#address" );
var selectType = options.filter( ":selected" ).attr( "value" );
address.autocomplete({
source: "ajaxSearchForClientAddress.php?selectType=" + selectType,
minLength: 3
});
select.change(function () {
selectType = options.filter( ":selected" ).attr( "value" );
address.autocomplete( "option", "source", "ajaxSearchForClientAddress.php?selectType=" + selectType );
});
});