bootstrap-select使用

罗寒
2023-12-01

<link rel="stylesheet" href="../../../statics/plugins/bootstrap-select-1.13.10/dist/css/bootstrap-select.css" />
<script src="../../../statics/plugins/bootstrap-select-1.13.10/dist/js/bootstrap-select.js"></script>

Select单选:

如果没有设置选中项,默认选中第一个option。如设置了tiltle属性,则显示title属性内容,不会默认选中。

<select class="selectpicker" title="大魔王">....</select>

添加样式:data-style=“class名”

<select class="selectpicker" data-style="btn-info">...</select>

添加检索:data-live-search=“true”

<select class="selectpicker" data-live-search="true">....</select>

Select多选:

添加“multiple ” 设置为多选,并且设置最多能选择2项 data-max-options=“2”

设置检索placeholder属性:data-live-search-placeholder=“搜索”

添加“全选/反选” 功能按钮 data-actions-box=“true”

<select class="selectpicker form-control" multiple data-max-options="2"></select>
<select class="selectpicker" multiple data-live-search="true" data-live-search-placeholder="搜索" data-actions-box="true">
  <optgroup label="filter1">
    <option>option1</option>
    <option selected>option2</option>
    <option>option3</option>
    <option>option4</option>
  </optgroup>
  <optgroup label="filter2">
    <option>option1</option>
    <option>option2</option>
    <option>option3</option>
    <option>option4</option>
  </optgroup>
  <optgroup label="filter3">
    <option>option1</option>
    <option>option2</option>
    <option>option3</option>
    <option>option4</option>
  </optgroup>
</select>

js初始化,设置选定的值

$('.selectpicker').selectpicker('val','mustard');

$('.selectpicker').selectpicker('val',['mustard','relish']);

更新

$('.selectpicker').selectpicker('refresh');
// 在使用 vue.js的时候,赋值完成后刷新无效可以尝试延时刷新
setTimeout(function(){
	$("#cellSelecters").selectpicker("refresh");
},1000)

选中事件

$('.selectpicker').on('changed.bs.select',function(e){});
 类似资料: