一个select双击切换效果

无聊写了一个简单的select双击切换效果...

让我把重点讲解下.

changeSelect(true,this.id);changeSelect(false,this.id);     //获取当前ID,true or false.

if(opt.selected)  //判断是否选中.

elem.removeChild(opt);  //删除当前select下的选中option

elem.nextSibling.nextSibling.appendChild(opt);  //把当前select下的选中option追加到下一个select下

elem.previousSibling.previousSibling.appendChild(opt);  //上一步相反.

好困啊.睡觉.

整体代码:

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>一个select双击切换效果</title>
</head>
<body>
<select ondblclick="changeSelect(true,this.id);" id="left" multiple="multiple">
<option value="0">left1</option>
<option value="1">left2</option>
<option value="2">left3</option>
</select>
<select ondblclick="changeSelect(false,this.id);" id="right" multiple="multiple">
<option value="0">right1</option>
<option value="1">right2</option>
<option value="2">right3</option>
</select>

<script type="text/javascript">
function changeSelect(b,id){
var $a = document.getElementById(id);
if(b ==true){
var elem=$a;
}
else{
var elem=$a;
}
for(var i=0;i<elem.options.length;i++)
{
var opt=elem.options[i];
if(b ==true){
if(opt.selected){
elem.removeChild(opt);
elem.nextSibling.nextSibling.appendChild(opt);
}
}
else{
if(opt.selected){
elem.removeChild(opt);
elem.previousSibling.previousSibling.appendChild(opt);
}
}
}
}
</script>



</body>
</html>



转载于:https://www.cnblogs.com/blueDream2011/archive/2011/10/15/2212776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值