【问题标题】:Boostrap multiselect select all checked by defaultBootstrap 多选全选默认选中
【发布时间】:2014-10-23 10:04:51
【问题描述】:

我使用带有选项的 bootstrap-multiselect (v0.9.8)

 includeSelectAllOption: true 

可以在页面加载时默认全选吗?

谢谢。

【问题讨论】:

    标签: twitter-bootstrap default selectall bootstrap-multiselect


    【解决方案1】:

    以下内容来自http://davidstutz.github.io/bootstrap-multiselect/,我目前正在将此解决方案与 bootstrap 3.3.1 和 bootstrap-multiselect v0.9.8 一起使用 请务必将 false 参数添加到“selectAll”函数,因为它允许您选择所有选项而无需先打开下拉菜单。

    示例 HTML:

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

    示例 javascript:

    $(function() {
    
        $('#my-multi-select').multiselect({
            includeSelectAllOption: true
        });
    
        $("#my-multi-select").multiselect('selectAll', false);
        $("#my-multi-select").multiselect('updateButtonText');
    
    });
    

    【讨论】:

    • 谢谢你,$("#my-multi-select").multiselect('updateButtonText');@
    • 这似乎不起作用。 “全选”复选框保持未选中状态。
    • 你能列出你使用的版本和代码sn-ps吗?
    【解决方案2】:

    使用 bootstrap-select V.1.12.4,解决方案更简单:

    示例 HTML:

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

    示例 javascript:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多