Boostrap multiselect select all checked by default

£可爱£侵袭症+ 提交于 2019-12-03 09:44:54

问题


i use bootstrap-multiselect (v0.9.8) with option

 includeSelectAllOption: true 

it is posible that select all to be checked by default when page is loaded?

thx.


回答1:


The following is taken from http://davidstutz.github.io/bootstrap-multiselect/, and I am currently using this solution with bootstrap 3.3.1 and bootstrap-multiselect v0.9.8 Be sure to add the false parameter to the 'selectAll' function as that permits you to select all the options without first opening the dropdown.

Example HTML:

<select class="multiselect" id="my-multi-select" name="options[]" multiple="multiple">
    <option>1</option>
    <option>2</option>
</select>

Example javascript:

$(function() {

    $('#my-multi-select').multiselect({
        includeSelectAllOption: true
    });

    $("#my-multi-select").multiselect('selectAll', false);
    $("#my-multi-select").multiselect('updateButtonText');

});



回答2:


With bootstrap-select V.1.12.4, the solution is simpler:

Example HTML:

<select class="selectpicker" id="my-multi-select" name="options[]" multiple>
    <option>1</option>
    <option>2</option>
</select>

Example javascript:

$(function() {
    $('#my-multi-select').selectpicker({
    });
    $("#my-multi-select").selectpicker('selectAll');
});


来源:https://stackoverflow.com/questions/26525739/boostrap-multiselect-select-all-checked-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!