【发布时间】:2014-03-24 05:11:16
【问题描述】:
我更改了#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
}
});
});
警报显示更新的值,但源中使用的相同选择器(国家代码)没有,我做错了什么?
【问题讨论】:
-
我解决了。源 url 第一次被呈现为字符串,这就是它没有在输入更改时更新的原因。所以解决方案是在source选项中传递一个匿名函数而不是字符串属性,并在source选项内部进行ajax调用。我会发布代码,但 stackoverflow 不允许我回答自己的问题。呜呜。
标签: jquery-ui autocomplete jquery-selectors refresh