JavaScript 省市级联效果
JavaScript 省市级联效果
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>省市级联效果</title> 5 6 <script type="text/javascript"> 7 function show() { 8 var citys = new Array(); 9 citys["湖北省"] = ["襄樊市", "武汉市", "随州市", "荆门市", "黄石市", "恩施市", "咸宁市", "仙桃市", "十堰市", "孝感市", "利川市"]; 10 citys["湖南省"] = ["长沙市", "吉首市", "湘潭市", "益阳市", "津市市", "洪江市", "怀化市", "冷水江市", "衡阳市", "郴州市", "永州市", "邵阳市", "岳阳市"]; 11 citys["广东省"] = ["广州市", "深圳市", "佛山市", "汕头市", "珠海市", "韶关市", "江门市", "湛江市", "惠州市", "中山市", "东莞市"]; 12 citys["北京市"] = ["朝阳区", "丰台区", "崇文区", "宣武区", "海淀区", "顺义区", "平谷区", "怀柔区", "房山区", "东城区", "西城区"]; 13 14 document.getElementById("shi").options.length = 1; 15 var sheng = document.getElementById("sheng").value; 16 var newCity; 17 if (sheng != "-=请选择=-") { 18 for (var i = 0; i < citys[sheng].length; i++) { 19 newCity = new Option(citys[sheng][i], citys[sheng][i]); 20 document.getElementById("shi").options.add(newCity); 21 } 22 } 23 } 24 25 </script> 26 27 </head> 28 <body> 29 <div> 30 <select id="sheng" onchange="show()"> 31 <option value="-=请选择=-">-=请选择=-</option> 32 <option value="湖北省">湖北省</option> 33 <option value="湖南省">湖南省</option> 34 <option value="广东省">广东省</option> 35 <option value="北京市">北京市</option> 36 </select> 37 <select id="shi"> 38 <option>-=请选择=-</option> 39 </select> 40 </div> 41 </body> 42 </html>
执着而坚韧的蜗牛,求知于珠海,在通往理想的道路上披荆砍刺,瘦小的身躯蕴含着独特的思维和丰富的表达.在思索中洞悉IT世界的变化.从意气风发的学生会成员到渐渐成熟的IT职业人,我准备好了,跟着我的心灵深处的渴望一起去创造IT神话!