jquery:可以dynamic地改变Autocomplete部件的来源?

问候,

我正在使用官方的自动完成jquery部件,并有麻烦dynamic更改variables(selectType)我通过查询string传递。 该variables将根据通过select框select哪个选项而改变。

$(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 }); }); 

尝试实际更改change事件的自动完成的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 ); }); });