级联-city
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>城市注册</title>
</head>
<body>
省份
<select name="sf">
<option value="s1">请选择</option>
</select>
城市
<select name="cs" onclick="choose()">
<option value="c1">请选择</option>
</select>
</body>
<script type="text/javascript">
var sf=["请选择","辽宁省","吉林省","黑龙江省"];
var cs=[["请选择"],["沈阳市","大连市","鞍山市","抚顺市"],["长春市","吉林市","白山市"],["哈尔滨市","大庆市","牡丹江市"]];
var sfselect=document.querySelector("select");
var csselect=document.querySelector("select[name='cs']");
for(var i=0;i<sf.length;i++){
var option=document.createElement("option");
option.innerHTML=sf[i];
option.value=i;
sfselect.appendChild(option);
}
function choose(){
csselect.innerHTML="";
for(var i=0;i<cs[sfselect.value].length;i++){
var option=document.createElement("option");
option.innerHTML=cs[sfselect.value][i];
option.value=i;
csselect.appendChild(option);
}
}
</script>
</html>