javascript省市联动
2015-09-23 16:27
489 查看
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>script</title>
<script tp="text/javascript">
var arr=new Array();
arr[arr.length]=[1,'北京市',null];
arr[arr.length]=[2,'四川省',null];
arr[arr.length]=[3,'福建省',null];
arr[arr.length]=[4,'浙江省',null];
arr[arr.length]=[16,'杭州市',4]
arr[arr.length]=[15,'北京市',1];
arr[arr.length]=[5,'成都市',2];
arr[arr.length]=[6,'福州市',3];
arr[arr.length]=[7,'厦门市',3];
arr[arr.length]=[8,'泉州市',3];
arr[arr.length]=[9,'漳州市',3];
arr[arr.length]=[10,'三明市',3];
arr[arr.length]=[11,'龙岩市',3];
arr[arr.length]=[12,'宁德市',3];
arr[arr.length]=[13,'莆田市',3];
arr[arr.length]=[14,'南平市',3];
function sb(tp){
if(tp=='shen'){
var shen=document.getElementById("shen");//获得省的下拉列表
shen.innerHTML='';//内容为空
var one='<option value=""></option>'//填充省的字符
for(var i=0; i<arr.length;i++){//遍历数组
var item=arr[i];//当前项
if(item[2]==null)//
one+='<option value='+item[0]+'>'+item[1]+'</option>';
}
shen.innerHTML=one;//填充新内容
}else if(tp=='shi'){//获得省份的Id
var three=document.getElementById("shen").value;
if(three=='')
return false;
var shi=document.getElementById("shi");//获取下拉列表
shi.innerHTML="";
var two='<option value=""></option>';
for(var i=0;i<arr.length;i++){
var item=arr[i];
if(item[2]==three)
two+='<option value='+item[0]+'>'+item[1]+'</option>'
}
shi.innerHTML=two;
}
}
</script>
</head>
<body style="text-align:center的;" onLoad="sb('shen')">
<form>
姓 名:<input type="text" name="name"><br/>
密 码:<input type="password" name="name"><br/>
省 份:<select id="shen" onChange="sb('shi')"></select><br/><br/>
城 市:<select id="shi"></select>
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>script</title>
<script tp="text/javascript">
var arr=new Array();
arr[arr.length]=[1,'北京市',null];
arr[arr.length]=[2,'四川省',null];
arr[arr.length]=[3,'福建省',null];
arr[arr.length]=[4,'浙江省',null];
arr[arr.length]=[16,'杭州市',4]
arr[arr.length]=[15,'北京市',1];
arr[arr.length]=[5,'成都市',2];
arr[arr.length]=[6,'福州市',3];
arr[arr.length]=[7,'厦门市',3];
arr[arr.length]=[8,'泉州市',3];
arr[arr.length]=[9,'漳州市',3];
arr[arr.length]=[10,'三明市',3];
arr[arr.length]=[11,'龙岩市',3];
arr[arr.length]=[12,'宁德市',3];
arr[arr.length]=[13,'莆田市',3];
arr[arr.length]=[14,'南平市',3];
function sb(tp){
if(tp=='shen'){
var shen=document.getElementById("shen");//获得省的下拉列表
shen.innerHTML='';//内容为空
var one='<option value=""></option>'//填充省的字符
for(var i=0; i<arr.length;i++){//遍历数组
var item=arr[i];//当前项
if(item[2]==null)//
one+='<option value='+item[0]+'>'+item[1]+'</option>';
}
shen.innerHTML=one;//填充新内容
}else if(tp=='shi'){//获得省份的Id
var three=document.getElementById("shen").value;
if(three=='')
return false;
var shi=document.getElementById("shi");//获取下拉列表
shi.innerHTML="";
var two='<option value=""></option>';
for(var i=0;i<arr.length;i++){
var item=arr[i];
if(item[2]==three)
two+='<option value='+item[0]+'>'+item[1]+'</option>'
}
shi.innerHTML=two;
}
}
</script>
</head>
<body style="text-align:center的;" onLoad="sb('shen')">
<form>
姓 名:<input type="text" name="name"><br/>
密 码:<input type="password" name="name"><br/>
省 份:<select id="shen" onChange="sb('shi')"></select><br/><br/>
城 市:<select id="shi"></select>
</form>
</body>
</html>
相关文章推荐
- JS一些方法
- JavaScript闭包
- javascript中的this
- js去掉字符串前后以及中间的空格
- 50道JavaScript经典题和解法(JS新手进...持续更新...)
- HTML+CSS+JavaScript语言重温感想
- 使用Typescript来写javascript
- TypeScript入门指南(JavaScript的超集)
- JavaScript学习笔记之JS函数(一)
- Angular JS笔记
- javascript之查找数组元素
- JavaScript语言标识符和保留字
- jsp自定义select选择标签和数据字典
- jsp中checkbox用法详解
- JS动态显示时间
- JS 内置对象
- js 去掉字符串前后空格
- javascript中的变量声明原则
- 自定义jsp标签: TagSupport与BodyTagSupport的区别 (转)
- 如何更专业的使用Chrome开发者工具