关于select联动的两种做法
2014-01-16 15:51
267 查看
第一种方法:
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);
}
}
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);
}
}
相关文章推荐
- 关于逆序对的两种做法(归并排序+树状数组c++)
- 关于JS获取select值的两种实现方法
- 关于select 联动
- 关于下拉框联动选择的做法
- 关于js的冒泡事件,和一款基于jQuery的联动Select下拉框
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- SqlServer关于select into 和 insert into select 两种表复制语句
- 关于JS获取select值的两种实现方法
- [收集]关于ucenter忘记创始人密码的两种做法
- 关于JS获取select值的两种实现方法
- JAVA EE 项目经常使用知识 之AJAX技术实现select下拉列表联动的两种使用方法(让你真正理解ajax)
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
- 关于AOP记录日志的做法
- 关于单链表的两种创建方式
- jQuery cxSelect 多级联动下拉菜单
- select into from和insert into select from两种表复制语句区别
- Subsequence POJ - 3061 (二分法和尺取法两种做法)
- hdu 4031 attack 树状数组 线段树 两种做法
- 利用JS实现JSF页面h:selectOneMenu的联动