【HTML】使用 JQuery 实现级联选择框

匿名 (未验证) 提交于 2019-12-02 20:32:16


代码:

<!DOCTYPE html> <html> 	<head> 		<meta charset="utf-8"> 		<title>201731061203+许嘉欣</title> 		<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script> 		<style> 			select{ 				border: 1px solid palevioletred; 				border-radius: 5px; 			} 			select:focus{ 				outline: none; 			} 		</style> 	</head> 	<body> 		<form name="form1" method="post"> 			省份:<select name="province" id="province" "changeSelect(this.selectedIndex)"></select> 			市区:<select name="city" id="city"></section> 		</form> 		<script> 			var arrpro=["请选择省份","河北省","四川省"]; 			var arrcit=[["请选择城市"],["石家庄","邯郸","唐山"],["成都","绵阳","德阳"]]; 			window.init; 			function init() 			{ 				var province=document.form1.province; 				var city=document.form1.city; 			    province.length=arrpro.length; 				for(var i=0;i<arrpro.length;i++) 				{ 					province.options[i].text=arrpro[i]; 					province.options[i].value=arrpro[i]; 				} 				var index=0; 				province.selectedIndex=index; 				city.length=arrcit[index].length; 				for(var i=0;i<arrcit[index].length;i++) 				{ 					city.options[i].text=arrcit[index][i]; 					city.options[i].value=arrcit[index][i]; 				} 			} 			function changeSelect(index) 			{ 				var city=document.form1.city; 				province.selectedIndex=index; 				city.length=arrcit[index].length; 				for(var i=0;i<arrcit[index].length;i++) 				{ 					city.options[i].text=arrcit[index][i]; 					city.options[i].text=arrcit[index][i]; 				} 			} 		</script> 	</body> </html> 
文章来源: https://blog.csdn.net/xjx19991226/article/details/89295665
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!