在页面加载上获取Bootstrap多选择的所有值



我很容易在变更事件上获得多选择的值,但在不进行任何更改的情况下无法获得值。它是无效的。

     $('#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");
                }
            });

on Initialized事件将在页面加载中获得所有选定的值。

$('#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"在此处称为。

最新更新