$.ajax({
type: 'get',
url: systemConfig.backendurl + '/api/fl/gettype?type=1',
async: false,
success: function(res) {
if (res.success) {
var select = $("#selectwrap");
var datas = res.data;
for (var i = 0; i < datas.length; i++) {
select.append("<option value='" + datas[i].code + "'>" +
datas[i].name + "</option>");
}
$('.selectpicker').selectpicker('val', ['07', '06', '08']);//设置回显值
$('.selectpicker').selectpicker('refresh');
$('.selectpicker').selectpicker('render');
console.log($('.selectpicker').selectpicker('val'));//打印选择的值
}
},
error: function(err) {
console.log(err)
}
})
$('.selectpicker').on('changed.bs.select', function() {//单击时方法
console.log('agja');
var val = $(this).val();
console.log($('.selectpicker').selectpicker('val'));
});
//html要引入bootstrap.min.js bootstrap-select.min.js bootstrap-select.min.css"
<select class="selectpicker" data-live-search="true" multiple id='selectwrap'></select>
网友评论