html下拉框之间的联动------一级分类和二级分类
html/js代码如下:
<html> <body> <select id="first" onChange="change()"> <option selected="selected">湖北</option> <option>广东</option> </select> <select id="second"> <option>黄冈</option> <option selected="selected">武汉</option> </select> <script> function change() { var x = document.getElementById("first"); var y = document.getElementById("second"); y.options.length = 0; // 清除second下拉框的所有内容 if(x.selectedIndex == 0) { y.options.add(new Option("黄冈", "0")); y.options.add(new Option("武汉", "1", false, true)); // 默认选中省会城市 } if(x.selectedIndex == 1) { y.options.add(new Option("深圳", "0")); y.options.add(new Option("广州", "1", false, true)); // 默认选中省会城市 y.options.add(new Option("肇庆", "2")); } } </script> </body> </html>
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。