根据jquery自动完成中选择的国家/地区管理城市?
//为了国家根据jquery自动完成中选择的国家/地区管理城市?,jquery,Jquery,//为了国家 var objCountries = []; var objSearchCountry = new Object(); objSearchCountry.CountryName = $("#txtCountry").val(); $.ajax({ type: "POST", url: "db.php?GetCountryList", data: {data:[]}, dataType: "json", async:false, suc
var objCountries = [];
var objSearchCountry = new Object();
objSearchCountry.CountryName = $("#txtCountry").val();
$.ajax({
type: "POST",
url: "db.php?GetCountryList",
data: {data:[]},
dataType: "json",
async:false,
success: function(response)
{
if(response.IsError)
alert(response.ErrorMessage);
else
objCountries = response;
},
error:function(response)
{
alert("Error: " + response.responseText);
}
});
var newObjCountry = [];
for (var indexCountry in objCountries)
newObjCountry.push(objCountries[indexCountry].CountryName);
$("#txtCountry").autocomplete({ source: newObjCountry });
当我选择任何国家时,我想要它的id,这样我就可以通过这个id,在城市中获得相关的城市
$("#txtCountry").blur(function()
{
//for city
var objCities = [];
var objSearch = new Object();
objSearch.city_name = $("#txtCity").val();
$.ajax({
type: "POST",
url: "db.php?GetCityList",
data: {data:[]},
dataType: "json",
async:false,
success: function(response)
{
if(response.IsError)
alert(response.ErrorMessage);
else
objCities = response;
},
error:function(response)
{
alert("Error: " + response.responseText);
}
});
var newObj = [];
for (var index in objCities)
newObj.push(objCities[index].city_name);
$("#txtCity").autocomplete({ source: newObj });
});
谢谢您需要的是在选择自动完成事件时使用 这是
您需要的是在选择自动完成事件时使用 这是
您可以使用$(“#txtCountry”).val();要获取Country val并将其传入数据到GetCityList方法,请执行以下操作。已尝试,但不起作用..:(您没有将国家ID存储在任何位置。当您创建自动完成时,它只包含国家名称。您需要一个select元素。在自动完成中,我同时获取countryid和CountryName是,但我假设元素
#txtCountry
是一个文本框?请在浏览器的开发工具中检查它是否包含任何数据。)如果没有,你只需要有一个值。你可能需要考虑使用一个选择而不是一个文本框。你可以使用$(“yxtxtNead”).Var()来获取国家VALL并将其传递给GETCITYLIST方法。尝试但不工作。(您没有将国家ID存储在任何位置。当您创建自动完成时,它只包含国家名称。您需要一个select元素。在自动完成中,我同时获取countryid和CountryName是,但我假设元素#txtCountry
是一个文本框?请在浏览器的开发工具中检查它是否包含任何数据。)如果没有,你只需要有一个值。你可能需要考虑使用一个选择而不是一个文本框。
select : function(e, ui){
alert("selected!" + ui.item.value);
//rest of the code after selection goes here
}