jquery 操作Listbox

function MoveListBoxToRight(leftname, rightname) {
    var size = $("#" + leftname + " option").size();
    var selsize = $("#" + leftname + " option:selected").size();
    if (size > 0 && selsize > 0) {
        $.each($("#" + leftname + " option:selected"), function(id, own) {
            var text = $(own).text();
            var tag = $(own).attr("tag");
            $("#" + rightname).prepend("<option tag=\"" + tag + "\">" + text + "</option>");
            $(own).remove();
            $("#" + leftname + "").children("option:first").attr("selected", true);
        });
    }
    $.each($("#" + rightname + " option"), function(id, own) {
        orderrole(rightname);
    });
}//将ListBox中的数据移动到另外一个ListBox中,leftname为ListBox的name,rightname为另外一个ListBox的name

function orderrole(name) {
    var size = $("#" + name + " option").size();
    var one = $("#" + name + " option:first-child");
    if (size > 0) {
        var text = $(one).text();
        var tag = parseInt($(one).attr("tag"));
        $.each($(one).nextAll(), function(id, own) {
            var nextag = parseInt($(own).attr("tag"));
            if (tag > nextag) {
                $(one).remove();
                $(own).after("<option tag=\"" + tag + "\">" + text + "</option>");
                one = $(own).next();
            }
        });
    }
}//对改变后的ListBox中的数据进行排序

原文地址:https://www.cnblogs.com/glj1203/p/1939240.html