網路上有很多範例,但很多都不能用,所以我把我找到經過實驗後可以使用的貼給大家做參考

 

listbox1放左邊

listbox2放右邊 是目標Listbox(Target Listbox)

function add(listbox1,listbox2) {
    $('select[name=' + listbox1 + '] option:selected').appendTo('#' + listbox2);
}


function addall(listbox1, listbox2) {
    $('select[name=' + listbox1 + '] option').appendTo('#' + listbox2);
}


function remove(listbox1, listbox2) {
    $('select[name=' + listbox2 + '] option:selected').appendTo('#' + listbox1);
}


function removeall(listbox1, listbox2) {
    $('select[name=' + listbox2 + '] option').appendTo('#' + listbox1);
}

function MoveDown(listbox) {

    var selectedOption = $('select[name=' + listbox + '] option:selected');

    var nextOption = $('select[name=' + listbox + '] option:selected').next("option");
    
    if ($(nextOption).text() != "") {

        $(selectedOption).remove();

        $(nextOption).after($(selectedOption));

    }

}

function MoveUp(listbox) {

    var selectedOption = $('select[name=' + listbox + '] option:selected');

    var prevOption = $('select[name=' + listbox + '] option:selected').prev("option");

    if ($(prevOption).text() != "") {

        $(selectedOption).remove();

        $(prevOption).before($(selectedOption));

    }

}

arrow
arrow
    全站熱搜

    包爾伯 發表在 痞客邦 留言(0) 人氣()