老师来看看我
来源:7-8 编程练习
金鱼眼
2020-08-16 15:20:57
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body onload="address()">
<form>
省份:
<!-- 请在此补充代码 -->
<select id="sheng" name="sheng" onchange="linkage()"></select>
市/区:
<!-- 请在此补充代码 -->
<select id="shi" name="shi"></select>
</form>
</body>
</html>
=========================================================================
=========================================================================
function address(){
var sheng=document.getElementById("sheng");
var shi=document.getElementById("shi");
var shengfen=["北京市","天津市","河北省","河南省"];
var shiqu=["朝阳区","西城区","石家庄","邯郸市","西青区","武清区","郑州市","开封市"];
selectAdd(sheng,shengfen,shengfen);
selectAdd(shi,shiqu,shiqu);
linkage();
}
function selectAdd(obj,name,value){
/*请在此补充代码*/
for(var i=0;i<name.length;i++){
obj.options.add(new Option(name[i],value[i]));
}
}
function linkage() {
var sheng=document.getElementById("sheng");
var shi=document.getElementById("shi");
var shengfen=sheng.value;
var shiqu;
if(shengfen=="北京市"){
shiqu=["朝阳区","西城区"];
}else if (shengfen=="天津市") {
shiqu=["西青区","武清区"];
}else if (shengfen=="河北省") {
shiqu=["石家庄","邯郸市"];
}else{
shiqu=["郑州市","开封市"];
}
shi.options.length=0;
selectAdd(shi,shiqu,shiqu);
}1回答
好帮手慕小尤
2020-08-16
已完成练习,棒棒哒!继续加油!
祝学习愉快!
相似问题