老师这题题目是这么做的吗,代码思路正确吗?

来源:7-8 编程练习

weixin_慕码人71622

2020-03-18 09:33:57

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
<title>Document</title>
    <script type="text/javascript" src="index.js"></script>
</head>
<body onload="address()">
<form>
省份:
<select id="province" onChange="linkage()"></select>
<!--  请在此补充代码 -->
市/区:
<select id="city" onChange="linkage()"></select>
<!--  请在此补充代码 -->
</form>
</body>
</html>

function address(){
     /*请在此补充代码*/  
     var province = document.getElementById("province");
     var city = document.getElementById("city");
     selectAdd(province, "北京市", "Beijing");
     selectAdd(province, "天津市", "Tianjin");
     selectAdd(province, "河北省", "Hebei");
     selectAdd(province, "河南省", "Henan");
     selectAdd(city,"朝阳区","CY");
     selectAdd(city,"西城区","XC");
}
function selectAdd(obj,name,value){
/*请在此补充代码*/ 
obj.options.add(new Option(name,value));
}
function linkage(){
/*请在此补充代码*/  
var provinceKey = document.getElementById("province");
var city = document.getElementById("city");
var province = provinceKey.value;
//  alert(svlaue);
if(province == "Beijing"){
    city.options.length=0;
    selectAdd(city,"朝阳区","CY");
     selectAdd(city,"西城区","XC");
}else if(province == "Tianjin"){
    city.options.length=0;
    selectAdd(city,"西青区","XQ");
     selectAdd(city,"武清区","WQ");
}else if(province == "Hebei"){
    city.options.length=0;
    selectAdd(city,"石家庄","Sjz");
     selectAdd(city,"邯郸市","Gd");
}else if(province =="Henan"){
    city.options.length=0;
    selectAdd(city,"郑州市","Zz");
     selectAdd(city,"开封市","Kf");
}
}


写回答

1回答

好帮手慕小脸

2020-03-18

你好,代码逻辑与结果是正确的,如果解决您的问题请采纳,祝学习愉快!

0

0 学习 · 9666 问题

查看课程