JavaScript二次元配列実現の省都連動メニュー
2443 ワード
Insert title here
<br>//
<br>var cities=[
<br>[" "," "," "],
<br>[" "," "," "],
<br>[" "," "," "]
<br>];
<br>// ,
<br>function provinceChanged(sel){
<br>//alert("select "+sel.options.length);
<br>//sel select
<br>// options ,
<br>for(var x=0;x<sel.options.length;x++)
<br>{
<br>var opt=sel.options[x];
<br>if(opt.selected)
<br>{
<br>// select option
<br>addCityToSelect(x)
<br>}
<br>}
<br>}
<br>// city select
<br>function addCityToSelect(x){
<br>//
<br>var city=cities[x-1];
<br>var citySelect=document.getElementById("select_city");
<br>/*================== ===============
<br> n select , 。
<br> 1:select removeChild(), 。
<br> 2: select.options.length=1 。
<br>*/
<br>// select options 1
<br>citySelect.options.length=1;
<br>// options ,
<br>//citySelect.options.length=1;
<br>for(var x=0;x<city.length;x++)
<br>{
<br>//
<br>var optionName=document.createElement("option");
<br>// option
<br>optionName.innerHTML=city[x];
<br>// option select
<br>citySelect.appendChild(optionName);
<br>/*
<br> citySelect
<br> ,
<br>citySelect 。 。 ,
<br> citySelect 。 :
<br>================== ===============
<br>*/
<br>}
<br>}
<br>