利用jquery实现省市区县3级联动



58 229 77



特效描述:利用jquery实现 省市区县 3级联动,利用jquery实现省市区县3级联动

代码结构

1. 引入CSS

<link rel="stylesheet" href="css.css" />
<link rel="stylesheet" href="form.css" />

2. 引入JS

<script src="kit.js"></script>
<script src="ieFix.js"></script>
<script src="dom.js"></script>
<script src="event.js"></script>
<script src="TreeDict.js"></script>
<script src="math.js"></script>
<script src="form.js"></script>
<script src="combobox.js"></script>
<script src="suggestselect.js"></script>
<script src="list.js"></script>
<script src="json-data.js" charset="utf-8"></script>

3. HTML代码

		<h1>国家省份城市联动</h1>
		<ul>
			<li>
				<span> 省份 </span>
				<select class="kitjs-form-suggestselect"></select>
				<span> 市/县 </span>
				<select class="kitjs-form-suggestselect"></select>
				<span> 区 </span>
				<select class="kitjs-form-suggestselect"></select>
			</li>
		</ul>
		<script>
			var a = $kit.els8cls($kit.ui.Form.ComboBox.Select.defaultConfig.transformCls), a1 = [];
			for(var i = 0; i < a.length; i++) {
				a1.push(a[i])
			}
			a = a1;
			var b1 = new $kit.ui.Form.ComboBox.Select({
				el : a[0],
				data : (function() {
					var provTreeDict = new TreeDict();
					for(var prov in chinaJSON) {
						provTreeDict.ad(prov, prov);
					}
					return provTreeDict;
				})()
			});
			b1.transform();
			b1.ev({
				ev : 'change',
				fn : function() {
					var prov = chinaJSON[b1.inputEl.value];
					if(prov == null) {
						return;
					}
					var cityTree = new TreeDict();
					for(var city in prov) {
						cityTree.ad(city, city);
					}
					b2.inputEl.value = '';
					b2.formEl.value = '';
					b2.config.data = cityTree;
					b2.list.buildList(cityTree.search(''));
				}
			});
			var b2 = new $kit.ui.Form.ComboBox.Select({
				el : a[1],
				data : undefined
			});
			b2.transform();
			b2.ev({
				ev : 'change',
				fn : function() {
					var city = chinaJSON[b1.inputEl.value][b2.inputEl.value];
					if(city == null) {
						return;
					}
					var districtTree = new TreeDict();
					for(var district in city) {
						districtTree.ad(district, city[district]);
					}
					b3.inputEl.value = '';
					b3.formEl.value = '';
					b3.config.data = districtTree;
					b3.list.buildList(districtTree.search(''));
				}
			});
			var b3 = new $kit.ui.Form.ComboBox.Select({
				el : a[2],
				data : undefined
			});
			b3.transform();
		</script>
<br><br><br><br><br><br><br><br>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 滑动星星打分 收缩收起展开 切换按钮 form表单 其他更多 收缩导航菜单 文本框 三级联动 城市选择 鼠标滑过

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到