需引入bootstrap-select.js和bootstrap-select.min.css,地址:https://gitee.com/jolone/source.git
select class=“selectpicker” multiple selectpicker和multiple属性的搭配使用可实现多选
data-live-search=“true” 这个属性的默认值是false,作用是打开模糊筛查搜索框。
data-max-options 这个属性表示最多可选几个,搭配multiple使用,
data-selected-text-forma缩略模式, 用法:data-selected-text-format=“count > 3”,
当选中值大于3个的时候只显示选中项的个数,注意只对多选生效。
data-style 表示默认选中样式,
data-size data-size=“6”,表示下拉框显示的下拉列表数量。
data-dropup-auto=“false”, 表示下拉框默认向下展开;“true”,表示下拉框默认向下展开;
<li>
<label class="label_name" th:text="${model.customer}"></label>
<div class='col-xs-8 col-sm-8'>
<select id ="customer"class="selectpicker" data-live-search="true">
<option data-tokens="ketchup mustard" value="0" th:text="${model.selectCustomer}"></option>
</select>
</div>
</li>
//检索客户
$("#customer").on('shown.bs.select',function(e){
var deviceStr="" ;
$.ajax({
type: "GET",
url: "cuSelectCustomer",
data: {},
async: false,
dataType: "json",
success: function (result) {
if (result.ok) {
for (var i = 0; i < result.data.length; i ++){
deviceStr+='<option value="' + result.data[i].customerId + '">' +result.data[i].name + '</option>';
}
}
},
error: function (XMLHttpRequest) {
layer.alert(messages.systemE, {
title: messages.promptBox,
icon: 0,
btn: messages.btn,
});
// alert("error" + XMLHttpRequest.readyState);
}
});
$("#customer").html("");
$('#customer').append(deviceStr);
$('#customer').selectpicker('refresh');
});