随笔 - 290  文章 - 10  评论 - 85  2
$(function () {

        function MoveItem(fromId, toId) {
            $("#" + fromId + " option:selected").each(function () {
                $(this).appendTo($("#" + toId + ":not(:has(option[value=" + $(this).val() + "]))"));
            });
            $("#" + fromId + " option:selected").remove();
        }

        //Add按钮
        $("#addUser").click(function () {
            var fromId = "User";
            var toId = "UserSelected";
            MoveItem(fromId, toId);
        });
        //Remove按钮
        $("#removeUser").click(function () {
            var fromId = "UserSelected";
            var toId = "User";
            MoveItem(fromId, toId);
        });

        //双击左边选项
        $('#User').dblclick(function () {
            var toId = "UserSelected";
            var fromId = "User";
            MoveItem(fromId, toId);
        });
        //双击右边选项
        $('#UserSelected').dblclick(function () {
            var fromId = "UserSelected";
            var toId = "User";
            MoveItem(fromId, toId);
        });
});

Jquery操作select,左右移动,双击移动

取到所有option的值

var str = $("#UserSelected option").map(function () { return $(this).val(); }).get().join(",")

 

  

posted on 2016-11-16 18:12  Gu  阅读(...)  评论(...编辑  收藏