2014-02-22 70 views
0

我更改#countrycode值,但$(#countrycode).val()沒有在「源」選項中刷新/更新,但它在警報jQuery 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)而不是,我做錯了什麼?

+0

我解決它。源URL首次被呈現爲字符串,這就是爲什麼它不更新輸入更改。所以解決方法是在source選項中傳遞一個匿名函數而不是字符串屬性,並在source選項中進行ajax調用。我會發布代碼,但stackoverflow不讓我回答自己的問題。的Bleh。 – Lemonade

回答

0

試試這個

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

它將使一個選項是選擇

相關問題