ajax版的 精简的三级联动

前端之家收集整理的这篇文章主要介绍了ajax版的 精简的三级联动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
$("#selProvince").change(function() {
$.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; }

原文链接:https://www.f2er.com/ajax/164729.html

猜你在找的Ajax相关文章