1.页面中嵌入selectpicker,需要将class属性设为“selectpicker”
<select id="bankname" class="selectpicker"><option>---请选择---</option></select>
2.利用ajax填充下拉框
$(".selectpicker").selectpicker({noneSelectedText:"请选择"}); //设置初始值
$.ajax({
url:contextPath + "/card/list",
type:"get",
dataType:"json",
success:function(result){
var cardVos = result.result;
for(var i=0;i<cardVos.length;i++){
var bankname = cardVos[i].bankname;
$("#bankname").append("<option>"+bankname+"</option>");
}
$(".selectpicker").selectpicker("refresh"); //数据填充后必须刷新select
},
error:function(result){
layer.msg(result['message']);
}
});