Jquery ui jQuery val()不会在更改时更新其值

Jquery ui jQuery val()不会在更改时更新其值,jquery-ui,autocomplete,jquery-selectors,refresh,Jquery Ui,Autocomplete,Jquery Selectors,Refresh,我更改了#countrycode值,但是$(#countrycode).val()不会在“源”选项中刷新/更新,但会在警报中更新 $( document ).ready(function() { //List cities with autocompelte $( "#city" ).autocomplete( { source:"autocomplete.php?countrycode=" + $("#countrycode").val(),

我更改了#countrycode值,但是$(#countrycode).val()不会在“源”选项中刷新/更新,但会在警报中更新

$( document ).ready(function() {

    //List cities with autocompelte
    $( "#city" ).autocomplete(
    {
        source:"autocomplete.php?countrycode=" + $("#countrycode").val(),
        select: function (event, ui) {          

            alert($("#countrycode").val()); //Test the countrycode selector
     }
    });
});
警报显示更新的值,但与源代码中使用的选择器(countrycode)相同。不是,我做错了什么

试试这个

$("#countrycode option:selected").prop("selected","false");
$("#countrycode option[value='".$("#countrycode").val()."']").prop("selected","true");

它将使正在选择的选项

I解决它。源url在第一次被呈现为字符串,这就是为什么它没有在输入更改时更新。因此,解决方案是在源选项中传递匿名函数而不是字符串属性,并在源选项中进行ajax调用。我会发布代码,但stackoverflow不让我回答我自己的问题。呜呜。