<head>
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../bootstrap/dist/css/bootstrap-select.css">
<script src="../assets/jquery.js"></script>
<script src="../bootstrap/js/bootstrap.bundle.js"></script>
<script src="../bootstrap/dist/js/bootstrap-select.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<button class="button primary" onclick="getAll()">获取选择的</button>
<select class="selectpicker col-6" id="sel" title="请选择" multiple data-live-search="false"
data-actions-box="true" data-max-options="5">
<option value="1">系统管理员</option>
<option value="2">销售</option>
<option value="3">客户经理</option>
<option value="4">技术经理</option>
<option value="5">人事</option>
</select>
</div>
</div>
<script>
function getAll() {
var value = $('#sel').val();
console.log(value)
initSel()
}
async function initSel() {
const daarr = await getDt();
$("#sel").empty();
daarr.forEach(element => {
$("#sel").append("<option value=" + element + " >" + element + "</option>");
});
$('#sel').selectpicker('refresh');
}
function getDt() {
let dataStr = '但如果,你提交,数据时将表,单序列化,个有更多的空,有足够,的空间可以正,常完全打开,但是上面,变成了一个下';
let daarr = dataStr.split(',');
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(daarr);
}, 2000);
})
}
</script>
.selectpicker('val')
$('.selectpicker').selectpicker('val', 'Mustard');
$('.selectpicker').selectpicker('val', ['Mustard','Relish']);
{# 回填数据,typeof Arr 为选中项value的值#}
$("#tester").selectpicker('val', ['typeof' ,'Arr' ]);
$("#tester").selectpicker('refresh');
.selectpicker('setStyle')
$('.selectpicker').addClass('col-lg-12').selectpicker('setStyle');
.selectpicker('refresh')
$('.selectpicker').selectpicker('refresh');