How to Set Selected value in Multi-Value Select in Jquery-Select2.?

后端 未结 14 922
轻奢々
轻奢々 2020-12-01 01:41

hi all i am binding my dropdown with Jquery-Select2. Its working fine but now i need to Bind my Multi-Value selectBox by using Jquery-Select2.

M

14条回答
  •  眼角桃花
    2020-12-01 01:50

    Well actually your only need $.each to get all values, it will help you jsfiddle.net/NdQbw/5

    The script:

     var selectedValues = new Array();
        selectedValues[0] = "a";
        selectedValues[1] = "c";
    
    $(".getValue").click(function() {
        alert($(".leaderMultiSelctdropdown").val());
    });
    $(".setValue").click(function() {
       $(".Books_Illustrations").val(selectedValues);
    });
    
    $('#drp_Books_Ill_Illustrations2, #drp_Books_Ill_Illustrations3').select2();
    
    
    $(".getValue1").click(function() {
        alert($(".leaderMultiSelctdropdown").val());
    });
    
    $(".setValue1").click(function() {
        //You need a id for set values
        $.each($(".Books_Illustrations"), function(){
                $(this).select2('val', selectedValues);
        });
    });
    

提交回复
热议问题