//如果区名没有填充数据,城市有选择数据则加载数据
if ($("select[id$=ddlAreaName] > option").length == 1 && $ddlcity.val() != "-1") {
loadWater($ddlcity.val(), "SelectAreaName");
//读cookie,有值则设为选中状态
var areaname = readCookie("JQ_AreaName");
if (areaname != null && areaname != "undefined" && areaname != "") {
$("select[id=ddlAreaName] > option[value='" + areaname + "']").attr("selected", "true");
}
}
$ddlarea.bind("change keyup", function() {
if ($(this).val() != "-1") {
//选中值存cookie
writeCookie("JQ_AreaName", $(this).val(), 0.5, true);
}
});
});
function loadWater(selectedItem, typename) {
$.ajax({
type: "GET",
url: "/GetWaterxiname.ashx",
data: { usetype: typename, id: selectedItem },
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function Success(data) {
bindWater(data, typename);
}
});
}
function bindWater(data, typename) {
if (typename == "SelectCity") { //绑定城市
$("select[name$=ddlCity] > option").remove(); //删除原有的option
$("select[id$=ddlCity]").append($("<option></option>").val("-1").html("--请选择--"));
for (var i = 0; i < data.length; i++) {
$("select[id$=ddlCity]").append($("<option></option>").val(data[i].City).html(data[i].City));
}
}
else if (typename == "SelectAreaName") {
$("select[name$=ddlAreaName] > option").remove(); //删除原有的option
$("select[id$=ddlAreaName]").append($("<option></option>").val("-1").html("--请选择--"));
for (var i = 0; i < data.length; i++) {
$("select[id$=ddlAreaName]").append($("<option></option>").val(data[i].AreaName).html(data[i].AreaName));
}
}
}
说明:省份数据在页面加载时绑定,页面提交后 省份值可以用 selectvalue取,市,区选中数据要用 Request["idname"] 获取
您可能感兴趣的文章: