【JS】实现单选框的左右移动

实现以下效果的:

<title>复选框</title>
<style>
.div1{
width:110px;
height:200px;
float:left;
text-align:center;
line-height:190px;
}


.s{
width:100px;
height:200px;
background-color:#99CCFF;
}
.s1{ background-color:#889EC4;
}
</style>
</head>


<body>
<div style=" width:350px; height:200px;position:absolute; left:350px;; top:20px;">
<div class="div1">
<select class="s" multiple name="ss1" id="ss1">
<option value="red" >红色</option>
<option value="blue">橙色</option>
<option value="green">黄色</option>
<option value="yellow">绿色</option>
<option value="orange">蓝色</option>
<option value="orange">青色</option>
<option value="orange">紫色</option>


</select>
</div>


<div class="div1">
<input class="s1" type="button" value="获取选中项索引" style="margin-top:60px;" οnclick="GetSelectedIndex();"><br />
<input class="s1" type="button" value=" >> " οnclick="AllSel(ss1,ss2);" /><br />
<input class="s1"type="button" οnclick="AllSel(ss2,ss1);" value=" << " />
</div>
<div class="div1">
<select class="s" multiple name="ss2" id="ss2">
</select>
</div></div>
</body>
<script language="javascript" type="text/javascript">
function GetSelectedIndex(){
var s11=document.getElementById("ss1");
var arr=new Array();
for(var i=0;i<s11.options.length;i++){
if(s11.options[i].selected)
//arr[]=i;//js动态数组不支持这种写法
arr.push(i);
}
alert(arr.length);
}
//第一个οnclick="AllSel(ss1,ss2);"

//第二个οnclick="AllSel(ss2,ss1);"

//我太爱这个函数了!

function AllSel(ss1,ss2)
{
  for(ss1.selectedIndex!=-1)
 {
 ss2.options.add(new Option(ss1.options[ss1.selectedIndex].text));
 ss1.remove(ss1.selectedIndex);
  }
}


</script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值