<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>城市註冊</title> </head> <body> 省份 <select name="sf"> <option value="s1">請選擇</option> </select> ...
<!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>