首页 > 其他 > 详细

关于select联动的两种做法

时间:2014-01-17 08:39:14      阅读:346      评论:0      收藏:0      [点我收藏+]

第一种方法:

function dong(){
      var getSheng = document.getElementById("sheng");
      var getShi = document.getElementById("shi");
      var where = getSheng.selectedIndex;
      for(var j=0;j<getShi.length;j++){//清除二级城市的选项
         getShi.remove(j);//用的是select的remove方法,j是option的索引值
         j--;
      }
      for(var i=0;i<honglongjiang[where].length;i++){//添加新二级城市选项
         var y=document.createElement(‘option‘);//先创建的option选项
         y.text=honglongjiang[where][i];//然后给option选项text属性值。
         getShi.add(y);//用select的add方法时行添加创建的option
      }
}

 

第二种方法:

function dong(){
      var getSheng = document.getElementById("sheng");
      var getShi = document.getElementById("shi");
      var where = getSheng.selectedIndex;
      getShi.length=0;//用select的length长度赋值0来清除下面的option。
      for(var i=0;i<chengshi[where].length;i++)//添加新二级城市选项
      {
         getShi.options[i]=new Option(chengshi[where][i]);//new Option(text,value);
      }
}

关于select联动的两种做法

原文:http://www.cnblogs.com/vbluebirdv/p/3522664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!