欢迎来到奇迪科技(深圳)有限公司,超值服务提供卓越产品!
网站制作前端JS实现省市联动代码演示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>省市级联效果</title> <script type="text/javascript"> function show() { var citys = new Array(); citys["湖北省"] = ["襄樊市", "武汉市", "随州市", "荆门市", "黄石市", "恩施市", "咸宁市", "仙桃市", "十堰市", "孝感市", "利川市"]; citys["湖南省"] = ["长沙市", "吉首市", "湘潭市", "益阳市", "津市市", "洪江市", "怀化市", "冷水江市", "衡阳市", "郴州市", "永州市", "邵阳市", "岳阳市"]; citys["广东省"] = ["广州市", "深圳市", "佛山市", "汕头市", "珠海市", "韶关市", "江门市", "湛江市", "惠州市", "中山市", "东莞市"]; citys["北京市"] = ["朝阳区", "丰台区", "崇文区", "宣武区", "海淀区", "顺义区", "平谷区", "怀柔区", "房山区", "东城区", "西城区"]; document.getElementById("shi").options.length = 1; var sheng = document.getElementById("sheng").value; var newCity; if (sheng != "-=请选择=-") { for (var i = 0; i < citys[sheng].length; i++) { newCity = new Option(citys[sheng][i], citys[sheng][i]); document.getElementById("shi").options.add(newCity); } } } </script> </head> <body> <div> <select id="sheng" onchange="show()"> <option value="-=请选择=-">-=请选择=-</option> <option value="湖北省">湖北省</option> <option value="湖南省">湖南省</option> <option value="广东省">广东省</option> <option value="北京市">北京市</option> </select> <select id="shi"> <option>-=请选择=-</option> </select> </div> </body> </html>
本文版权所有,转载须注明:来源 https://www.qvdv.net/qvdv-oop-778.html