javascript实现省 市、区二级联动
<!DOCTYPE html>
<html lang="en">
<head>
<style>
select{
width: 100px;
height:20px;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body onload="getProvice()" onload="getCity()">
省份<select id="pro" onchange="getCity()"></select>
城市、区<select id="cit"></select>
<script>
var provice=[["---请选择---"],"河南","江苏","北京"];
var city=[[],["南阳","信阳","平顶山","郑州"],["苏州","宿迁","常州","镇江"],["东城区","西城区","朝阳区","昌平区"]];
//alert(provice[1]);
function getProvice(){
str="";
for(i=0;i<provice.length;i++){
str=str+"<option>"+provice[i]+"</option>";
}
document.getElementById("pro").innerHTML=str;
}
function getCity(){
var index = document.getElementById("pro").selectedIndex;
str="";
for(i=0;i<city[index].length;i++){
str=str+"<option>"+city[index][i]+"</option>";
}
document.getElementById("cit").innerHTML=str;
}
</script>
</body>
</html>