你好,
我正在使用官方的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
});
});
最佳答案
尝试在更改事件上实际更改自动完成功能的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 );
});
});