JavaScript省市區三級聯動菜單效果_javascript技巧

來源:互聯網
上載者:User

本文執行個體為大家分享了三級聯動省市區js完整代碼,供大家參考,具體內容如下

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script type="text/javascript"> var cityList = new Array(); var quList = new Array(); cityList['北京'] = [ '北京' ]; cityList['浙江'] = [ '杭州市', '溫州市', '金華市', '臨安市' ]; cityList['陝西'] = [ '西安', '寶雞', '鹹陽' ]; cityList['甘肅'] = [ '蘭州市', '武威市', '酒泉市', '張掖市' ]; quList['北京'] = [ '1區', '2區', '3區', '4區' ]; quList['杭州市'] = [ '5區', '6區', '7區', '8區' ]; quList['溫州市'] = [ '9區', '10區', '11區', '12區' ]; quList['西安'] = [ '13區', '14區', '15區', '16區' ]; quList['寶雞'] = [ '17區', '18區', '19區', '20區' ]; quList['蘭州市'] = [ '21區', '22區', '23區', '24區' ]; window.onload = allData; function allData() { var shengfen = document.getElementById('shengfen'); for ( var sf in cityList) { shengfen.add(new Option(sf, sf)); } } function changeCity() { var chengshi = document.getElementById('chengshi'); var sheng = document.getElementById('shengfen').value; chengshi.options.length = 1; for ( var cs in cityList[sheng]) { chengshi.add(new Option(cityList[sheng][cs], cityList[sheng][cs])); } } function changequ() { var shiqu = document.getElementById('shiqu'); var cheng = document.getElementById('chengshi').value; shiqu.options.length = 1; for ( var sh in quList[cheng]) { shiqu.add(new Option(quList[cheng][sh], quList[cheng][sh])); } }</script></head><body> <br /> <select id="shengfen" style="width:100px" onchange="changeCity()"><option>--選擇省份--</option> </select> <select id="chengshi" style="width:100px" onchange="changequ()"><option>--選擇城市--</option> </select> <select id="shiqu" style="width:100px"><option>--選擇區縣--</option> </select> </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.