- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <script type="text/javascript">
-
- function change()
- {
- var arr = [["---选择城市---"],
- ["海淀区","朝阳区","东城区","西城区"],
- ["广州","深圳","东莞","珠江"],
- ["长沙","湘潭","株洲","邵阳"],
- ["济南","青岛","烟台","威海"],
- ["沈阳","大连","鞍山","抚顺"]
- ];
-
- var selNode = document.getElementById("sel");
- var index = selNode.selectedIndex;
- var citys = arr[index];
-
- var subNode = document.getElementById("subsel");
-
- //删除subsel里面的所有的option项
- for(var x=0;x<subNode.options.length;x++)
- {
- subNode.remove(subNode.options[x]);
- }
-
- for(var x=0;x<citys.length;x++)
- {
- var optNode = document.createElement("option");
- optNode.innerText = citys[x];
- subNode.appendChild(optNode);
- }
- }
- </script>
- </head>
- <body>
- <select id="sel" onchange="change()">
- <option>---选择省市---</option>
- <option>北京</option>
- <option>广东</option>
- <option>湖南</option>
- <option>山东</option>
- <option>辽宁</option>
- </select>
- <select id="subsel">
- <option>---选择城市---</option>
- </select>
- </body>
- </html>
复制代码 |