菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
205
0

下拉框二级联动

原创
05/13 14:22
阅读数 36683
<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>

 

发表评论

0/200
205 点赞
0 评论
收藏