JScript实现地址选择功能
程序员文章站
2022-05-26 08:21:24
本文实例为大家分享了jscript实现地址选择功能的具体代码,供大家参考,具体内容如下
...
本文实例为大家分享了jscript实现地址选择功能的具体代码,供大家参考,具体内容如下
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script> var shenarr = new array(5); shenarr["广东"] = ["广州","深圳","韶关","汕头","茂名"]; shenarr["湖南"] = ["长沙","张家界","株洲","岳阳","吉首"]; shenarr["湖北"] = ["武汉","宜昌","荆州","黄冈","仙桃"]; shenarr["安徽"] = ["合肥","黄山"]; shenarr["河南"] = ["郑州","开封","洛阳","信阳"]; function getshen(){ var s = document.getelementbyid("shen"); for(var v in shenarr){ //把数组键加入到省的下拉框 s.add(new option(v,v),null); } } function getcity(){ var s = document.getelementbyid("shen"); var c = document.getelementbyid("city"); var v = s.value;//省份的名称,也是数组中的键 c.options.length = 0;//把城市下拉框中的项清除 //循环把某一个省的城市加入到市的下拉框 for(var i in shenarr[v] ){ c.add(new option(shenarr[v][i],shenarr[v][i]),null); } } </script> </head> <body onload="getshen()"> 省:<select id="shen" onchange="getcity()"> <option value="0">--请选择--</option> </select> 市:<select id="city"></select> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。