1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <select id="sheng"> <option value="省份">省份</option> <option value="河南省">河南省</option> <option value="浙江省">浙江省</option> </select> <select id="city"> <option value="市区">市区</option> </select> </body> </html>
<script type="text/javascript"> var arr1 = ["郑州市", "洛阳市", "驻马店市", "焦作市", "南阳市", "新乡市", "开封市", "漯河市", "濮阳市", "安阳市"]; var arr2 = ["杭州市", "金华市", "义乌市", "温州市", "绍兴市", "宁波市", "嘉兴市"]; sheng.onchange = function(){
var l = city.children.length; for(var i = 0; i < l; i++){ city.children[0].remove(); } var tempArray = ["市区"]; if(this.value == "河南省"){ tempArray = arr1; } if(this.value == "浙江省"){ tempArray = arr2; } for(var i = 0; i < tempArray.length; i++){ var option1 = document.createElement("option"); option1.innerHTML = tempArray[i]; option1.value = tempArray[i]; city.appendChild(option1); } console.log(tempArray); } </script>
|