如何在我的multiselect下拉列表中更改onChange中的所有選定值。使用的插件here。嘗試使用以下,但我認爲我是在錯誤的軌道bootstrap multiselect獲取選定值
$('#multiselect1').multiselect({
selectAllValue: 'multiselect-all',
enableCaseInsensitiveFiltering: true,
enableFiltering: true,
maxHeight: '300',
buttonWidth: '235',
onChange: function(element, checked) {
var brands = $('#multiselect1 option:selected');
var selection = [];
$(brands).each(function(index, brand){
selection.push(brand);
});
console.log(selection);
}
});
發現
$('#multiselect1').multiselect({
selectAllValue: 'multiselect-all',
enableCaseInsensitiveFiltering: true,
enableFiltering: true,
maxHeight: '300',
buttonWidth: '235',
onChange: function(element, checked) {
var brands = $('#multiselect1 option:selected');
var selected = [];
$(brands).each(function(index, brand){
selected.push([$(this).val()]);
});
console.log(selected);
}
});
對於解決方案+1,但是您在selected.push語句中出現錯誤。您將選項值的列表而不是字符串推送。你想刪除封閉的括號。 – tbradley22