<div class="codetitle"> <span><a style="CURSOR: pointer" data="78911" class="copybut" id="copybut78911" onclick="doCopy('code78911')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code78911"> <br> <br> <br> <br><title>json</title> <br><script type="text/javascript"> <BR><!-- <BR>var list=[{"name":"中国", <BR>"value":"86", <BR>"province":[{"name":"湖北", <BR>"value":"430000", <BR>"city":[{"name":"武汉","value":"wh"}, <BR>{"name":"黄冈","value":"hg"}, <BR>{"name":"襄阳","value":"xy"}]}, <BR>{"name":"河北", <BR>"value":"100000", <BR>"city":[{"name":"邯郸","value":"hd"}, <BR>{"name":"保定","value":"bd"}, <BR>{"name":"石家庄","value":"sjz"}]}, <br><br>{"name":"湖南", <BR>"value":"440000", <BR>"city":[{"name":"长沙","value":"cs"}, <BR>{"name":"株洲","value":"zz"}, <BR>{"name":"衡阳","value":"hy"}]}]}, <BR>{"name":"美国", <BR>"value":"22", <BR>"province":[{"name":"阿肯色", <BR>"value":"990000", <BR>"city":[{"name":"纽约","value":"ny"}, <BR>{"name":"华盛顿","value":"hsd"}, <BR>{"name":"波士顿","value":"bsd"}]}, <br><br>{"name":"阿哈哈", <BR>"value":"980000", <BR>"city":[{"name":"AA","value":"ahd"}, <BR>{"name":"BB","value":"abd"}, <BR>{"name":"CC","value":"asjz"}]}] <br><br>}]; <br><br>function init(){ <BR>var _country=document.getElementById("country"); <BR>for(var e in list){ <BR>var opt_1=new Option(list[e].name,list[e].value); <BR>_country.add(opt_1); <BR>} <BR>} <br><br><br><br>function toProvince(){ <BR>var _country=document.getElementById("country"); <BR>var _province=document.getElementById("province"); <BR>var _city=document.getElementById("city"); <BR>var v_country=_country.value; <br><br>_province.options.length=1; <BR>_city.options.length=1; <br><br>for(var e in list){ <BR>if(list[e].value==v_country){ <BR>for( var p in list[e].province){ <BR>var opt_2=new Option(list[e].province[p].name,list[e].province[p].value); <BR>_province.add(opt_2); <br><br>} <BR>break; <BR>} <BR>} <BR>} <br><br><BR>function toCity(){ <BR>var _country=document.getElementById("country"); <BR>var _province=document.getElementById("province"); <BR>var _city=document.getElementById("city"); <br><br>var v_country=_country.value; <BR>var v_province=_province.value; <br><br>//_province.options.length=1; <BR>_city.options.length=1; <br><br><BR>for(var e in list){ <BR>if(list[e].value==v_country){ <BR>for( var p in list[e].province){ <BR>//alert(list[e].province[p].value); <BR>if(list[e].province[p].value==v_province){ <BR>// alert(list[e].province[p].value); <BR>for(var cc in list[e].province[p].city){ <BR>var opt_3=new Option(list[e].province[p].city[cc].name,list[e].province[p].city[cc].value); <BR>_city.add(opt_3); <BR>} <br><br>return; <BR>} <br><br><BR>} <BR>break; <BR>} <BR>} <BR>} <br><br>//--> <BR></script> <br> <br><br> <br><select id="country" onchange="toProvince();"> <br><option value="-1">--请选择国家---</option> <br></select> <br><select id="province" onchange="toCity();"> <br><option value="-1">--请选择省份---</option> <br></select> <br><select id="city"> <br><option value="-1">--请选择市区---</option> <br></select> <br><br> <br> <br> </div>