急急急!! 用js编了个下拉菜单 但是用网页显示不了菜单下的内容 求解决办法
这是代码<!DOCTYPE><html><head><metahttp.equir="Content·Type"content="text/html;charset=ut...
这是代码
<!DOCTYPE>
<html>
<head>
<meta http.equir="Content·Type" content="text/html;charset=utf·8" />
<title>名字</title>
</head>
<body>
省:
<select id="p" onchange="sel_p()"></select>
市:
<select id="c" onchange="sel_c()"></select>
区县:
<select id="r"></select>
<script>
var area ={
"北京市":{"市区":["海淀区","朝阳区","丰台区"],"县":["密云县"]},
"广州省":{"广州":["天河区","白云区","试试区"],"深圳":["福田区","谢谢区"]},
"青海省":{"西宁":["城东区","城西区","城北区"],"格尔木":["昆仑路街道","黄河路街道"]}
};
//先加载数据。省份默认选择北京市,市默认市区,区县默认是海淀
var p = document.getElementById("p");
for(var k in area){
p.add(new Option(k,k));
}
var c = document.getElementById("c");
for(var k in area)["北京市"]){
c.add(new Option(k,k));
}
var r = document.getElementById("r");
for(var k in area["北京市"]["市区"]){
r.add(new Option(area["北京市"]["市区"][k],area["北京市"]["市区"][k]));
}
function sel_p(){
c.length = 0;
for(var k in area[p.value]){
c.add(new Option(k,k));
}
r.length = 0;
for(var k in area[p.value][c.value]){
r.add(new Option(area[p.value][c.value][k],area[p.value][c.value][k]));
}
}
function sel_c(){
r.length = 0;
for(var k in area[p.value][c.value]){
r.add(new Option(area[p.value][c.value][k],area[p.value][c.value][k]));
}
}
</script> 展开
<!DOCTYPE>
<html>
<head>
<meta http.equir="Content·Type" content="text/html;charset=utf·8" />
<title>名字</title>
</head>
<body>
省:
<select id="p" onchange="sel_p()"></select>
市:
<select id="c" onchange="sel_c()"></select>
区县:
<select id="r"></select>
<script>
var area ={
"北京市":{"市区":["海淀区","朝阳区","丰台区"],"县":["密云县"]},
"广州省":{"广州":["天河区","白云区","试试区"],"深圳":["福田区","谢谢区"]},
"青海省":{"西宁":["城东区","城西区","城北区"],"格尔木":["昆仑路街道","黄河路街道"]}
};
//先加载数据。省份默认选择北京市,市默认市区,区县默认是海淀
var p = document.getElementById("p");
for(var k in area){
p.add(new Option(k,k));
}
var c = document.getElementById("c");
for(var k in area)["北京市"]){
c.add(new Option(k,k));
}
var r = document.getElementById("r");
for(var k in area["北京市"]["市区"]){
r.add(new Option(area["北京市"]["市区"][k],area["北京市"]["市区"][k]));
}
function sel_p(){
c.length = 0;
for(var k in area[p.value]){
c.add(new Option(k,k));
}
r.length = 0;
for(var k in area[p.value][c.value]){
r.add(new Option(area[p.value][c.value][k],area[p.value][c.value][k]));
}
}
function sel_c(){
r.length = 0;
for(var k in area[p.value][c.value]){
r.add(new Option(area[p.value][c.value][k],area[p.value][c.value][k]));
}
}
</script> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询