1.本文內(nèi)容由于實際工作中遇到的問題椅野,而網(wǎng)上的教程基本是一摸一樣氮发,但是沒寫解決實際問題的根本操作而寫本文凡资,具體的一些代碼也是網(wǎng)上的砸捏,自己就懶得寫啦哈哈哈。
操作步驟
- 需要引用jquery
- 需要引用bootstrap
- 需要引用bootstrap-select 的css 與js
- 設(shè)置你實際代碼 select 的屬性 class="selectpicker bla bla bli" data-live-search="true" 加入到你的select標簽中
*大多數(shù) 例子是這個class="selectpicker bla bla bli" multiple data-live-search="true" 但multiple不知道有啥用 *
5.設(shè)置
<script type="text/javascript">
$(window).on('load', function () {
//在這個里面設(shè)置你代碼中select 的屬性
$('.selectpicker').selectpicker({
// 'selectedText': 'cat' 不需要的代碼
});
// $('.selectpicker').selectpicker('hide'); 不需要的代碼
});
</script>
the-blockchain_-1200x630-c-ar1.91.jpg
實際代碼
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<!-- 先需要引用jquery -->
<script type="text/javascript" src="http://www.daimajiayuan.com/download/jquery/jquery-1.10.2.min.js"></script>
<!-- 需要引用bootstrap -->
<link rel="stylesheet">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- <link rel="stylesheet">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> -->
<!-- 需要引用bootstrap-select 的css 與js -->
<link href="css/bootstrap-select.css" rel="stylesheet">
<script src="js/bootstrap-select.js"></script>
<!-- 重要的js代碼 其中.selectpicker 就是select標簽的類 class="selectpicker bla bla bli" 在加上data-live-search="true"
晚上大多數(shù)文檔就到這里沒具體說名怎么使用到實際應(yīng)用當中害的我調(diào)半天
其實就是簡單的把 class="selectpicker bla bla bli" data-live-search="true" 加入到你的select標簽中
-->
<!-- 這段代碼中寫你設(shè)置 select 的屬性 class="selectpicker bla bla bli" data-live-search="true" 加入到你的select標簽中 -->
<script type="text/javascript">
$(window).on('load', function () {
$('.selectpicker').selectpicker({
// 'selectedText': 'cat' 不需要的代碼
});
// $('.selectpicker').selectpicker('hide'); 不需要的代碼
});
</script>
</head>
<body>
<label for="id_select">Test label YEag</label>
<!-- 一般的要求做成這樣就好了如果需要其的深入研究需要自己研究 -->
<select id="id_select" class="selectpicker bla bla bli" data-live-search="true">
<option>cow</option>
<option>bull</option>
<option>ox</option>
<!-- <optgroup label="test" data-subtext="another test" data-icon="icon-ok">
<option>ASD</option>
<option selected>Bla</option>
<option>Ble</option>
</optgroup> -->
</select>
<div class="container">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="bs3Select" class="col-lg-2 control-label">Test bootstrap 3 form</label>
<div class="col-lg-10">
<select id="bs3Select" class="selectpicker show-tick form-control" data-live-search="true">
<option>cow</option>
<option>bull</option>
<option class="get-class" disabled>ox</option>
<!-- 這是下一部分其他展示效果 -->
<optgroup label="test" data-subtext="another test" data-icon="icon-ok">
<option>ASD</option>
<option selected>Bla</option>
<option>Ble</option>
</optgroup>
</select>
</div>
</div>
<form>
</div>
</body>
</html>