好吧,实际上,您只需要$ .each即可获取所有值,它将帮助您
jsfiddle.net/NdQbw/5
<div > <select id="drp_Books_Ill_Illustrations" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a" selected>Illustrations</option> <option value="b">Maps</option> <option value="c" selected>selectedPortraits</option> </select> </div><div > <select id="drp_Books_Ill_Illustrations1" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a">Illustrations</option> <option value="b">Maps</option> <option value="c">selectedPortraits</option> </select></div><button >Get Value</button><button > Set value </button><div > <select id="drp_Books_Ill_Illustrations2" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a" selected>Illustrations</option> <option value="b">Maps</option> <option value="c" selected>selectedPortraits</option> </select></div><div > <select id="drp_Books_Ill_Illustrations3" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a">Illustrations</option> <option value="b">Maps</option> <option value="c">selectedPortraits</option> </select></div><button >Get Value</button><button > Set value </button>
剧本:
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); });});


