javaScript實現三級菜單級聯

來源:互聯網
上載者:User
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><script language="javascript">//定義省份包含的城市數組var cityList= new Array();//選中省份的下標var provinceIndex;//顯示二級連function selectCity(){cityList['山東省']=['濟南','菏澤','青島'];cityList['河南省']=['商丘','鄭州','駐馬店'];cityList['四川省']=['成都','綿陽','自貢'];//獲得第一級聯的索引provinceIndex=document.form1.selProvince.value;var op;//清空第二級聯和三級聯,顯示預設選中值document.form1.selCity.options.length=1;document.form1.selChengzhen.options.length=1;//迴圈讀取份省包含城市的份數組,添加到第二級聯for(var i in cityList[provinceIndex]) {op=new Option(cityList[provinceIndex][i],cityList[provinceIndex][i]);document.form1.selCity.options.add(op);}}//選擇城鎮---三級聯function selctChengzhen(){//cityList['山東省']= new Array();cityList['山東省']['菏澤']=['成武縣','單縣','曹縣','定陶','東營','日本縣'];cityList['山東省']['青島']=['市北區','四方區','市南區','城陽區','李滄區'];cityList['山東省']['濟南']=['濟南1','濟南2','濟南3','濟南4','濟南5','濟南6'];cityList['河南省']['商丘']=['商丘1','商丘2','商丘3','商丘4','商丘5','商丘6'];cityList['河南省']['鄭州']=['鄭州1','鄭州2','鄭州3','鄭州4','鄭州5'];cityList['河南省']['駐馬店']=['駐馬店1','駐馬店2','駐馬店3','駐馬店4','駐馬店5','駐馬店6'];cityList['四川省']['綿陽']=['綿陽1','綿陽2','綿陽3','綿陽4','綿陽5','綿陽6'];cityList['四川省']['自貢']=['自貢1','自貢2','自貢3','自貢4','自貢5'];cityList['四川省']['成都']=['成都1','成都2','成都3','成都4','成都5','成都6'];//提取二級連選中的值var cityIndex=document.form1.selCity.value;var oopp;//清空第三級聯的列表document.form1.selChengzhen.options.length=1;//迴圈讀取添加到三級聯for(var j in cityList[provinceIndex][cityIndex]){oopp=new Option(cityList[provinceIndex][cityIndex][j],cityList[provinceIndex][cityIndex][j]);document.form1.selChengzhen.options.add(oopp);}}</script></head><body><form id="form1" name="form1" method="post" action="">  <select name="selProvince" id="select" onchange="selectCity()">      <option value="山東省" >山東省</option>      <option value="河南省" >河南省</option>      <option value="四川省" >四川省</option>      <option value=""selected="selected">--請選擇省份--</option>  </select>  <select name="selCity" id="select2" onchange="selctChengzhen()">  <option value=""selected="selected">--請選擇城市--</option>  </select>  <select name="selChengzhen" id="select3">  <option value=""selected="selected">--請選擇市縣--</option>  </select></form></body></html>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.