省份级联简单示例
程序员文章站
2022-06-08 10:01:02
...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script type="text/javascript"> var sf = new Array(); sf[0] = new Array("0","--请选择省份--"); var gd = new Array(); gd[0] = new Array("0","广东"); gd[1] = new Array("1","深圳"); var zj = new Array(); zj[0] = new Array("0","杭州"); zj[1] = new Array("1","宁波") function showCity(pe){ for (var i=0; i<pe.length;i++){ document.f.city.options[i] = new Option(pe[i][1],pe[i][0]); } } function choose(){ var tag = document.f.p.value; switch(tag){ case '0':init();showCity(sf);break; case '1':init();showCity(gd);break; case '2':init();showCity(zj);break; } } function init(){ var len = document.f.city.options.length; for (var i = 0; i<len; i++){ document.f.city.remove(i); } } function flush(){ document.f.p.options[0].selected = true; } </script> </head> <body onload="flush()"> <h1>省市级联</h1> <form name="f"> <select name="p" onchange="choose()"> <option value="0" selected>--省份</option> <option value="1">广东</option> <option value="2">浙江</option> </select> <select name="city"> <option value="0">城市</option> </select> </form> </body> </html>
上一篇: 写点 什么
下一篇: 这是怎么搞的 企业应用