三级联动-完美版
<script src="http://pic.51.com/i/js/GlobalProvinces.js?v=20080321"></script>
<script type="text/javascript">
function changeProvince() {
gpm.initCity1(document.getElementById('User_Town'), gpm.getSelValue(document.getElementById('User_Shen')));
gpm.initCity2(document.getElementById('User_City'), '', '');
}
function changeTown() {
gpm.initCity2(document.getElementById('User_City'), gpm.getSelValue(document.getElementById('User_Shen')), gpm.getSelValue(document.getElementById('User_Town')));
}
</script>
<select id="User_Shen" name="User_Shen" tabindex="6" onchange="changeProvince();" >
<option value="0">省/市</option>
<option value="安徽" >安徽</option>
<option value="北京" >北京</option>
<option value="重庆" >重庆</option>
<option value="福建" >福建</option>
<option value="甘肃" >甘肃</option>
<option value="广东" >广东</option>
<option value="广西" >广西</option>
<option value="贵州" >贵州</option>
<option value="海南" >海南</option>
<option value="河北" >河北</option>
<option value="黑龙江" >黑龙江</option>
<option value="河南" >河南</option>
<option value="湖北" >湖北</option>
<option value="湖南" >湖南</option>
<option value="内蒙古" >内蒙古</option>
<option value="江苏" >江苏</option>
<option value="江西" >江西</option>
<option value="吉林" >吉林</option>
<option value="辽宁" >辽宁</option>
<option value="宁夏" >宁夏</option>
<option value="青海" >青海</option>
<option value="山西" >山西</option>
<option value="陕西" >陕西</option>
<option value="山东" >山东</option>
<option value="上海" >上海</option>
<option value="四川" >四川</option>
<option value="天津" >天津</option>
<option value="西藏" >西藏</option>
<option value="新疆" >新疆</option>
<option value="云南" >云南</option>
<option value="浙江" >浙江</option>
<option value="香港" >香港</option>
<option value="澳门" >澳门</option>
<option value="台湾" >台湾</option>
<option value="海外">海外</option>
</select>
-
<select id="User_Town" name="User_Town" tabindex="6" onchange="changeTown();">
<option value="0">市/地区</option>
</select>
-
<select id="User_City" name="User_City" tabindex="6">
<option value="0">县/市</option>
</select>
<script language="javascript" type="text/javascript">
var gpm = new GlobalProvincesModule;
gpm.def_province = ["省/市", ""];
gpm.def_city1 = ["市/地区", ""];
gpm.def_city2 = ["县/市", ""];
gpm.initProvince(document.getElementById('User_Shen'));
gpm.initCity1(document.getElementById('User_Town'), gpm.getSelValue(document.getElementById('User_Shen')));
document.getElementById('User_Town').value = "";
gpm.initCity2(document.getElementById('User_City'), gpm.getSelValue(document.getElementById('User_Shen')), gpm.getSelValue(document.getElementById('User_Town')));
document.getElementById('User_City').value = "";
</script>
<script type="text/javascript">
function changeProvince() {
gpm.initCity1(document.getElementById('User_Town'), gpm.getSelValue(document.getElementById('User_Shen')));
gpm.initCity2(document.getElementById('User_City'), '', '');
}
function changeTown() {
gpm.initCity2(document.getElementById('User_City'), gpm.getSelValue(document.getElementById('User_Shen')), gpm.getSelValue(document.getElementById('User_Town')));
}
</script>
<select id="User_Shen" name="User_Shen" tabindex="6" onchange="changeProvince();" >
<option value="0">省/市</option>
<option value="安徽" >安徽</option>
<option value="北京" >北京</option>
<option value="重庆" >重庆</option>
<option value="福建" >福建</option>
<option value="甘肃" >甘肃</option>
<option value="广东" >广东</option>
<option value="广西" >广西</option>
<option value="贵州" >贵州</option>
<option value="海南" >海南</option>
<option value="河北" >河北</option>
<option value="黑龙江" >黑龙江</option>
<option value="河南" >河南</option>
<option value="湖北" >湖北</option>
<option value="湖南" >湖南</option>
<option value="内蒙古" >内蒙古</option>
<option value="江苏" >江苏</option>
<option value="江西" >江西</option>
<option value="吉林" >吉林</option>
<option value="辽宁" >辽宁</option>
<option value="宁夏" >宁夏</option>
<option value="青海" >青海</option>
<option value="山西" >山西</option>
<option value="陕西" >陕西</option>
<option value="山东" >山东</option>
<option value="上海" >上海</option>
<option value="四川" >四川</option>
<option value="天津" >天津</option>
<option value="西藏" >西藏</option>
<option value="新疆" >新疆</option>
<option value="云南" >云南</option>
<option value="浙江" >浙江</option>
<option value="香港" >香港</option>
<option value="澳门" >澳门</option>
<option value="台湾" >台湾</option>
<option value="海外">海外</option>
</select>
-
<select id="User_Town" name="User_Town" tabindex="6" onchange="changeTown();">
<option value="0">市/地区</option>
</select>
-
<select id="User_City" name="User_City" tabindex="6">
<option value="0">县/市</option>
</select>
<script language="javascript" type="text/javascript">
var gpm = new GlobalProvincesModule;
gpm.def_province = ["省/市", ""];
gpm.def_city1 = ["市/地区", ""];
gpm.def_city2 = ["县/市", ""];
gpm.initProvince(document.getElementById('User_Shen'));
gpm.initCity1(document.getElementById('User_Town'), gpm.getSelValue(document.getElementById('User_Shen')));
document.getElementById('User_Town').value = "";
gpm.initCity2(document.getElementById('User_City'), gpm.getSelValue(document.getElementById('User_Shen')), gpm.getSelValue(document.getElementById('User_Town')));
document.getElementById('User_City').value = "";
</script>
发现一个严重问题:
我将此段代码复制到用.net新建的htm或aspx页面里,就会出错。(提示:GlobalProvincesModule 未定义)
而粘贴在文本文件,再重命名。运行则不会出错。
目前还不知道是什么原因。如果有哪位知道,请告之。。谢谢。。
终于解决了,原来是编码问题,那个JS的编码是gb2312,而.net创建的页面默认是utf-8,所以出错了。呵呵
幸亏一个高手帮忙看了下。不然。郁闷的惨。