将一个select中的内容移动到另一个select中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<div class="centent">
        <select multiple id="select1" style="width:130px;height:180px;">
            <option value="1">孙克杰</option>
            <option value="2">朱信宗</option>
            <option value="3">杨帆</option>
            <option value="4">林非比</option>
            <option value="5">亚历山大</option>
            <option value="6">凌峰</option>
            <option value="7">宋松</option>
            <option value="8">王子瑜</option>
        </select>
        <div class="span1">
            <span id="add">右移>></span><br/>
            <span id="add_all">全部>></span>
        </div>
    </div>
    <div class="centent"
        <select multiple id="select2" style="width:130px;height:180px">
         
        </select>
        <div class="span2">
            <span id="remove" style="width:500px">左移<<</span><br/>
            <span id="remove_all">全部<<</span>
        </div>
    </div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<style type="text/css">
    span{
        border:1px solid black;
        background-color:#99FFFF;
        cursor:pointer;
    }
    .centent{
        width:200px;
        float:left;
    }
    .span1{
        position:absolute;
        top:350px;
        left:150px;
    }
    #add_all{
        position:absolute;
        top:30px;
    }
    .span2{
        position:absolute;
        top:410px;
        left:150px;
    }
    #remove_all{
        position:absolute;
        top:30px;
    }
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script>
$(function(){      
    $("#add").click(function(){
        var $options = $("#select1 option:selected");//获取选中的选项
        $options.appendTo("#select2");//追加到select2的select中
    });
    $("#add_all").click(function(){
        var $options = $("#select1 option");
        $options.appendTo("#select2");
    });
    //实现双击时,右移
    $("#select1").dblclick(function(){
        var $options = $("#select1 option:selected");
        $options.appendTo("#select2");
    });
     
    $("#remove").click(function(){
        var $options = $("#select2 option:selected");
        $options.appendTo("#select1");
    });
    $("#remove_all").click(function(){
        var $options = $("#select2 option");
        $options.appendTo("#select1");
    });
    $("#select2").dblclick(function(){
        var $options = $("#select2 option:selected");
        $options.appendTo("#select1");
    });
});
</script>



本文转自 爱笑嘚蛋蛋 51CTO博客,原文链接:http://blog.51cto.com/dd118/1671376,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值