两个下拉列表框value值相互转移

[size=medium][size=medium]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtmlSelect.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<script type="text/javascript">
window.οnlοad=function(){
/*******************************右移********************************************/
document.getElementById("button3").οnclick=function(){
var firstSelect= document.getElementById("select"); //第一个下拉框
var twoSelect= document.getElementById("select1"); //第二个下拉框
var optionfirst=firstSelect.getElementsByTagName("option"); //获得的是一个数组
var len=optionfirst.length;
for(var i=0;i<len;i++){
var optionName=optionfirst[i];//获得所有的 option 里面的值
//
//必须将选中的移动,,所以
// alert(firstSelect.selectedIndex); //没有被选中的 下标 永远都是-1,选中的为该当前下标
if(firstSelect.selectedIndex!=-1){
twoSelect.appendChild(optionfirst[firstSelect.selectedIndex]);
}
}
}

/*******************************左移********************************************/
document.getElementById("button2").οnclick=function(){
var firstSelect= document.getElementById("select"); //第一个下拉框
var twoSelect= document.getElementById("select1"); //第二个下拉框
var optionfirst=twoSelect.getElementsByTagName("option"); //获得的是一个数组
var len=optionfirst.length;
for(var i=0;i<len;i++){
var optionName=optionfirst[i];//获得所有的 option 里面的值
//
//必须将选中的移动,,所以
// alert(firstSelect.selectedIndex); //没有被选中的 下标 永远都是-1,选中的为该当前下标
if(twoSelect.selectedIndex!=-1){
firstSelect.appendChild(optionfirst[twoSelect.selectedIndex]);
}
}
}

/*******************************全部右移********************************************/
document.getElementById("button4").οnclick=function(){
var firstSelect= document.getElementById("select"); //第一个下拉框
var twoSelect= document.getElementById("select1"); //第二个下拉框
var optionfirst=firstSelect.getElementsByTagName("option"); //获得的是一个数组
var len=optionfirst.length;
for(var i=0;i<len;i++){
twoSelect.appendChild(optionfirst[0]);
}

}


/*******************************全部左移********************************************/
document.getElementById("button").οnclick=function(){
var firstSelect=document.getElementById("select1");

//第一个下拉框
var twoSelect= document.getElementById("select"); //第二个下拉框
var optionfirst=firstSelect.getElementsByTagName("option"); //获得的是一个数组
var len=optionfirst.length;
for(var i=0;i<len;i++){
twoSelect.appendChild(optionfirst[0]);//只要控制移动的下标为0 就移动
}

}

/*******************************双击移动到右边********************************************/
document.getElementById("select").οndblclick=function(){
var first=this.getElementsByTagName("option");
var twoSelect= document.getElementById("select1"); //第二个下拉框
for(var i=0;i<first.length;i++){
twoSelect.appendChild(first[this.selectedIndex])

}
}

/*******************************双击移动到左边 实现的重要的一个原理是找选中的下标即this.selectedIndex ********************************************/
document.getElementById("select1").οndblclick=function(){
/*var first=this.getElementsByTagName("option");
var twoSelect= document.getElementById("select"); //第二个下拉框
for(var i=0;i<first.length;i++){
twoSelect.appendChild(first[this.selectedIndex])
} */

//优化后的。。。
var first=this.getElementsByTagName("option");
alert(this.selectedIndex);
var twoSelect= document.getElementById("select");
twoSelect.appendChild(this[this.selectedIndex]);
}



}

</script>



</head>

<body>
<div>
<select name="select" size="15" multiple="multiple" id="select" >
<option value="数学">数学</option>
<option value="语文">语文</option>
<option value="外语">外语</option>
<option value="物理">物理</option>
<option value="化学">化学</option>
<option value="生物">生物</option>
<option value="历史">历史</option>
</select>
<input type="submit" name="button2" id="button2" value="《《左移" />
<input type="submit" name="button3" id="button3" value="右移》》" />
<input type="submit" name="button4" id="button4" value="全部右移》》" />
<input type="submit" name="button" id="button" value="《《全部左移" />
<select name="select2" size="15" multiple="multiple" id="select1" >

</select>
<br/>
<br/>
</div>
</body>
</html>[/size]
[/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值