$.ajax({
type: "GET",
url: "/handler/pcdprovider/getcitylist_1_0.ashx",
data: { proid: this.value },
success: function(data) {
var selcity = $("#selCity");
$("#selDistrict").html("<option value='0'>选择所在区县</option>");
selcity.empty();
data = eval(data);
for (var i = 0; i < data.length; i++) {
selcity.append("<option value='" + data[i].CityID + "'>" + data[i].City_CN + "</option>");
}
},
error: function(e) { }
});
});
$("#selCity").change(function() {
$.ajax({
type: "GET",
url: "/handler/pcdprovider/getdistrictlist_1_0.ashx",
data: { cityid: this.value },
success: function(data) {
var selDistrict = $("#selDistrict");
selDistrict.empty();
data = eval(data);
for (var i = 0; i < data.length; i++) {
selDistrict.append("<option value='" + data[i].AreaID + "'>" + data[i].District_CN + "</option>");
}
},
error: function(e) { }
});
});
//选定某项
for(var i=0 ;i<document.getElementById("selDist").options.length;i++)
{
if(document.getElementById("selDist").options[i].value*1 == city*1)
{
document.getElementById("selDist").options[i].selected = true;
break;
}
}
一般处理程序
public void ProcessRequest(HttpContext context) { int provinceId = WebHelper.GetQueryStringValue<int>(ResourceKeys.ProvinceId,0); List<CityEntity> CityList = GetHotCityList(provinceId); CityList.Insert(0,new CityEntity() { CityID = 0,City_CN = "选择所在城市" }); context.Response.ContentType = "application/json"; context.Response.Write(SerializationHelper.SerializeJSON(CityList)); context.Response.End(); } /// <summary> /// 城市数据转换 /// </summary> /// <param name="provinceId"></param> /// <returns></returns> protected List<CityEntity> GetHotCityList(int provinceId) { List<CityEntity> plist = new List<CityEntity>(); List<mc.CityEntity> ve = AdminiArea.GetCityList(provinceId); foreach (mc.CityEntity item in ve) { CityEntity ce = new CityEntity(); ce.CityID = item.CityID; ce.City_CN = item.City_CN; plist.Add(ce); } return plist; }