级联下拉列表

//根据所选的省,自动生成对应的市

<html>
	<head>
		<title>级联列表</title>
		<meta http-equiv='Content-Type' content='text/css;charset=utf-8'/>
		<style>
			.yemian{
				margin-left:30%;
				text-align:center;
				font-size:50px;
				width:500px;
				height:500px;
				background-color:blue;
			}   
			.s{
				width:120px;
				height:25px;
			}
		</style>
		<script>
			function st(){
			
				var sheng=document.getElementById('sheng');
				//存省的数组,可自行添加
				var shengs=new Array(new Option("--请选择省--",''),new Option("湖南","hn"),new Option("广东","gd"));
				for(var i=0;i<shengs.length;i++){
					sheng.options[i]=shengs[i];
				}
			}
			//存市的数组,根据省的数组添加
			var shis=new Array();
			shis[0]=new Array(new Option("--请选择市--",''));
			shis[1]=new Array(new Option("长沙",'cs'),new Option("娄底",'ld'),new Option("永州",'yz'));
			shis[2]=new Array(new Option("广州",'gz'),new Option("深圳",'sz'));
			function change(obj){
				var shi=document.getElementById('shi');
				shi.options.length=0;
				var index=sheng.selectedIndex;
				for(var x in shis[index]){
					shi.options[x]=shis[index][x]
				}
			}
		</script>
	</head>
	<body  οnlοad="st()">
		<div class='yemian' >
			<div class="top">级联下拉列表</div>
			<select class='s' id='sheng' οnchange='change(this)'>
				<option value=''>--请选择省--</option>
			</select>
			<select class='s' id='shi'>
				<option value=''>--请选择市--</option>
			</select>
		</div>
	</body>


</html>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值