twitter-bootstrap Boostrap 多选全选默认选中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26525739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Boostrap multiselect select all checked by default
提问by rozatrra
i use bootstrap-multiselect (v0.9.8) with option
我使用 bootstrap-multiselect (v0.9.8) 和选项
includeSelectAllOption: true
it is posible that select all to be checked by default when page is loaded?
是否可以在加载页面时默认选择所有要检查的内容?
thx.
谢谢。
回答by noahpc
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.
以下内容取自http://davidstutz.github.io/bootstrap-multiselect/,我目前正在使用此解决方案与 bootstrap 3.3.1 和 bootstrap-multiselect v0.9.8 请务必将 false 参数添加到 'selectAll ' 功能允许您选择所有选项而无需先打开下拉列表。
Example HTML:
示例 HTML:
<select class="multiselect" id="my-multi-select" name="options[]" multiple="multiple">
<option>1</option>
<option>2</option>
</select>
Example javascript:
示例javascript:
$(function() {
$('#my-multi-select').multiselect({
includeSelectAllOption: true
});
$("#my-multi-select").multiselect('selectAll', false);
$("#my-multi-select").multiselect('updateButtonText');
});
回答by CFP Support
With bootstrap-select V.1.12.4, the solution is simpler:
使用 bootstrap-select V.1.12.4,解决方案更简单:
Example HTML:
示例 HTML:
<select class="selectpicker" id="my-multi-select" name="options[]" multiple>
<option>1</option>
<option>2</option>
</select>
Example javascript:
示例javascript:
$(function() {
$('#my-multi-select').selectpicker({
});
$("#my-multi-select").selectpicker('selectAll');
});

