<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.ElementElement"); ); <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"); =document.getElementById("city"); <BR><br>var v_country=_country.value; <br>var v_province=_province.value; <BR><br>//_province.options.valueth=1; 🎜>_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><br> </div>