zoukankan      html  css  js  c++  java
  • js05-省市联动

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script>
    			var provinces = [
    						["深圳","广州","中山","珠海"],
    						["长沙","岳阳","郴州","株洲"],
    						["武汉","黄冈","黄石","宜昌"]
    						]
    			
    			function selectCity(){
    				var province = document.getElementById("sheng")   //得到当前省份
    //				alert(province.value) 
    				var cities = provinces[province.value]        //城市列表
    				
    				var citySelect = document.getElementById("city")     //定位到 城市 select
    				citySelect.options.length = 0
    				for (var i = 0;i<cities.length;i ++) {
    					var citytext = cities[i]        // 获取每一个城市
    //					alert(citytext)
    					var option1 = document.createElement("option")
    					var text = document.createTextNode(citytext)
    					option1.appendChild(text)
    					citySelect.appendChild(option1)
    				}
    			}
    		</script>
    	</head>
    	<body>		
    		籍贯:
    		<select id="sheng" onchange="selectCity()">
    			<option selected="selected">请选择</option>
    			<option value="0">广东省</option>
    			<option value="1">湖南省</option>
    			<option value="2">湖北省</option>
    		</select>
    		<select id="city">
    			
    		</select>
    			
    		
    	</body>
    </html>
    

      

    竹杖芒鞋轻胜马,一蓑烟雨任平生。 回首向来萧瑟处,也无风雨也无晴。
  • 相关阅读:
    Leetcode86.分隔链表
    Leetcode39.组合总和
    Leetcode31.下一个排列
    剑指Offer35.复杂链表复制
    剑指Offer14-I.剪绳子
    剑指Offer38.字符串的排序
    Leetcode29.两数相除
    232. Implement Queue using Stacks
    程序员跳槽指南
    226. Invert Binary Tree
  • 原文地址:https://www.cnblogs.com/yaobiluo/p/13200221.html
Copyright © 2011-2022 走看看