省市二级联动(省市字典表)

//添加省option

function addProvinceOption() {
//根据id查找对象
var obj = document.getElementById('provinceid');
//添加选项
$.post("/system/ProvinceDictionaryList.json", function(data) {
data = data.rows;
$("#provinceid").empty();
for (var i = 0; i < data.length; i++) {
obj.options.add(new Option(data[i].value, data[i].id));
}
});
}
//添加市option

function addCityOption() {
//根据id查找对象
var obj = document.getElementById('cityid');
//添加选项
var provinceid = $("#provinceid").val();
if (provinceid != null || provinceid != "") {
$.post("/system/CityDictionaryList.json", {
parentId: provinceid
}, function(data) {
data = data.rows;
$("#cityid").empty();
for (var i = 0; i < data.length; i++) {
obj.options.add(new Option(data[i].value, data[i].id));
}
});
}
}

posted @ 2017-06-26 15:05  武力对白  阅读(1240)  评论(0编辑  收藏  举报