我很容易在更改事件中获取multiselect的值,但无法在不进行任何更改的情况下获取值。它是空的。
$('#multiselct').multiselect({
includeSelectAllOption: true,
// To get selected values on page load
onInitialized: function(select, container) {
selected = this.$select.val();
},
// To get selected value on change
onChange: function () {
selected = this.$select.val();
},
// To get selected values on select all
onSelectAll: function () {
selected = this.$select.val();
console.log("select-all-nonreq");
},
// To get selected values on deselect
onDeselectAll: function () {
selected = this.$select.val();
console.log("deselect-all-nonreq");
}
});
OnInitialized事件将获取页面加载中的所有选定值。
答案 0 :(得分:0)
$('#multiselectbox').multiselect({
onOptionClick( element, option ){
// On Option Click
},
onSelectAll( element, selected ){
// On SelectAll Option
},
onLoad(element){
// On Load It will call
// To Get the Selected Options
var selected_options = $(element).val();
console.log( selected_options );
}
});
希望这对您有用。在“加载页面”上,此处称为“ onLoad”。