省市区数据变动少,我们可以基于JSON数据构建select控件中的选项,建立三级联动的下拉框,引用附件中的JS文件:

whir.area.zip


Html结构:

<select id="selProvince">
    <option value="">--请选择--</option>
</select>
<select id="selCity">
    <option value="">--请选择--</option>
</select>
<select id="selDistrict">
    <option value="">--请选择--</option>
</select>


JS写法:

var $selProvince = $("#selProvince");
var $selCity = $("#selCity");
var $selDistrict = $("#selDistrict");
whir.area.bindDropDownList($selProvince, 0, function() {
    whir.area.bindDropDownList($selCity, $selProvince.val(), function() {
        whir.area.bindDropDownList($selDistrict, $selCity.val());
    });
    $selDistrict.html("--请选择--");
});


赋值:

var takeRegion = "";
if (takeRegion) {
    var district = whir.area.getAreaById(takeRegion);
    var city = whir.area.getAreaById(district.ParentID);
    var province = whir.area.getAreaById(city.ParentID);
    $selProvince.val(province.ID);
    whir.area.bindDropDownList($selCity, province.ID);
    $selCity.val(city.ID);
    whir.area.bindDropDownList($selDistrict, city.ID);
    $selDistrict.val(district.ID);
    $tdTakeRegion.html(province.Name + city.Name + district.Name);
}