在页面加载时获取Bootstrap multiselect的所有值。

问题描述 投票:0回答:1

我很容易在改变事件中获得多选的值,但在没有做任何改变的情况下无法获得值。它的值是空的。

     $('#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事件会在页面加载时获得所有选择的值。

jquery twitter-bootstrap bootstrap-multiselect
1个回答
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"。

© www.soinside.com 2019 - 2024. All rights reserved.