最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于jquery & json的省市區(qū)聯(lián)動代碼

 更新時間:2012年06月26日 20:34:43   作者:  
基于jquery & json的省市區(qū)聯(lián)動代碼,需要的朋友可以參考下
效果演示:



html代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>省市區(qū)聯(lián)動</title>
<script src="/Scripts/jquery.min.js" type="text/javascript"></script>
<script src="/Scripts/script.js" type="text/javascript"></script>
</head>
<body>
<h2>Demo:</h2>
<select id="province">
<option value="0">請選擇省份</option>
</select>
<select id="city">
<option value="0">請選擇城市</option>
</select>
<select id="district">
<option value="0">請選擇區(qū)縣</option>
</select>

<!--下列為初始值(可選,編輯表單時設(shè)置)-->
<input type="hidden" value="440000" id="pre_province"/>
<input type="hidden" value="440500" id="pre_city"/>
<input type="hidden" value="440511" id="pre_district"/>

</body>
</html>


script.js代碼:

復(fù)制代碼 代碼如下:

/*
author: elycir
create: 2012-06
description: 省市區(qū)三級(二級)聯(lián)動
*/
$(function () {
var citySelector = function () {
var province = $("#province");
var city = $("#city");
var district = $("#district");
var preProvince = $("#pre_province");
var preCity = $("#pre_city");
var preDistrict = $("#pre_district");
var jsonProvince = "/content/json-array-of-province.js";
var jsonCity = "/content/json-array-of-city.js";
var jsonDistrict = "/content/json-array-of-district.js";
var hasDistrict = true;
var initProvince = "<option value='0'>請選擇省份</option>";
var initCity = "<option value='0'>請選擇城市</option>";
var initDistrict = "<option value='0'>請選擇區(qū)縣</option>";
return {
Init: function () {
var that = this;
that._LoadOptions(jsonProvince, preProvince, province, null, 0, initProvince);
province.change(function () {
that._LoadOptions(jsonCity, preCity, city, province, 2, initCity);
});
if (hasDistrict) {
city.change(function () {
that._LoadOptions(jsonDistrict, preDistrict, district, city, 4, initDistrict);
});
province.change(function () {
city.change();
});
}
province.change();
},
_LoadOptions: function (datapath, preobj, targetobj, parentobj, comparelen, initoption) {
$.get(
datapath,
function (r) {
var t = ''; // t: html容器
var s; // s: 選中標(biāo)識
var pre; // pre: 初始值
if (preobj === undefined) {
pre = 0;
} else {
pre = preobj.val();
}
for (var i = 0; i < r.length; i++) {
s = '';
if (comparelen === 0) {
if (pre !== "" && pre !== 0 && r[i].code === pre) {
s = ' selected=\"selected\" ';
pre = '';
}
t += '<option value=' + r[i].code + s + '>' + r[i].name + '</option>';
}
else {
var p = parentobj.val();
if (p.substring(0, comparelen) === r[i].code.substring(0, comparelen)) {
if (pre !== "" && pre !== 0 && r[i].code === pre) {
s = ' selected=\"selected\" ';
pre = '';
}
t += '<option value=' + r[i].code + s + '>' + r[i].name + '</option>';
}
}

}
if (initoption !== '') {
targetobj.html(initoption + t);
} else {
targetobj.html(t);
}
},
"json"
);
}
};
} ();
citySelector.Init();
});

省市區(qū)json數(shù)據(jù)文件:點(diǎn)擊下載

相關(guān)文章

最新評論

昌宁县| 黄大仙区| 弋阳县| 临夏市| 湖南省| 南江县| 乌鲁木齐县| 鄂伦春自治旗| 通河县| 华安县| 云浮市| 沧州市| 磐安县| 盘锦市| 陵川县| 昌吉市| 工布江达县| 武乡县| 沧州市| 黄梅县| 苍山县| 长子县| 白银市| 布拖县| 剑阁县| 义马市| 天台县| 五指山市| 宁阳县| 名山县| 和龙市| 临城县| 连城县| 社会| 兴业县| 黄浦区| 沅江市| 旅游| 吴川市| 宣武区| 廊坊市|