官网文档地址.里面的demo 用到了goole的一些JS.看效果需要代理
http://silviomoreto.github.io/bootstrap-select/methods/
加nuget包.
增加JS和CSS两个文件.
前台
<select id="mySelect_UserGorups" multiple title="----Choose----" data-width="280px" class="selectpicker"> @*<option value="0">Mustard</option> <option value="1">Ketchup</option> <option value="2">Relish</option>*@ </select> <input type="button" onclick="sel_Init();" value="sel_Init" class="btn btn-success" /> <input type="button" onclick="sel_GetChecked();" value="sel_Getchecked" class="btn btn-success" /> <input type="button" onclick="sel_SetCheck();" value="sel_SetCheck" class="btn btn-success" />
js
<script> //初始化 function sel_Init() { //清空数据 $("#mySelect_UserGorups").empty(); var str = ""; //循环 for (var i = 0; i < 3; i++) { $("#mySelect_UserGorups").append($("<option>").val(i + 'a').text("i" + i)); } //单条 var option = $("<option>").val(3).text("pxx"); $("#mySelect_UserGorups").append(option); $('#mySelect_UserGorups').selectpicker('refresh'); } //get值 function sel_GetChecked() { console.log($('#mySelect_UserGorups').selectpicker('val')); } //set值 function sel_SetCheck() { $('#mySelect_UserGorups').selectpicker('val', ['0a', '1a']); } </script>
一些效果