如我所愿,只要单击选择选项,下拉菜单就会加载图标
要求:BootStrap版本4.1.0需要实现同一段代码。到目前为止,只要单击选择下拉列表都不会出现。
实际输出:以下代码在BootStrap 3.3.4版中可以完美运行
$(document).ready(function() {
// Initiate with custom caret icon
$('select.selectpicker').selectpicker({
caretIcon: 'glyphicon glyphicon-menu-down'
});
});
body {
margin: 2em;
}
pre {
margin: 1em 0;
}
select.selectpicker {
display: none;
/* Prevent FOUC */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://thdoan.github.io/bootstrap-select/js/bootstrap-select.js"></script>
<link rel="stylesheet" href="https://thdoan.github.io/bootstrap-select/css/bootstrap-select.css">
<h2>Select with Icons</h2>
<select title="Select your spell" class="selectpicker">
<option>Select...</option>
<option data-icon="glyphicon glyphicon-eye-open" data-subtext="petrification">Eye of Medusa</option>
<option data-icon="glyphicon glyphicon-fire" data-subtext="area damage">Rain of Fire</option>
</select>
预期的输出:BootStrap版本4.1.0需要实现同一段代码
$(document).ready(function() {
// Initiate with custom caret icon
$('select.selectpicker').selectpicker({
caretIcon: 'glyphicon glyphicon-menu-down'
});
});
body {
margin: 2em;
}
pre {
margin: 1em 0;
}
select.selectpicker {
display: none;
/* Prevent FOUC */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://thdoan.github.io/bootstrap-select/js/bootstrap-select.js"></script>
<link rel="stylesheet" href="https://thdoan.github.io/bootstrap-select/css/bootstrap-select.css">
<h2>Select with Icons</h2>
<select title="Select your spell" class="selectpicker">
<option>Select...</option>
<option data-icon="glyphicon glyphicon-eye-open" data-subtext="petrification">Eye of Medusa</option>
<option data-icon="glyphicon glyphicon-fire" data-subtext="area damage">Rain of Fire</option>
</select>
答案 0 :(得分:1)
您未添加正确版本的bootstrap.js
您没有添加popper.js
您未添加正确版本的bootstrap-select.js
由于Bootstrap 4不支持Glyphicon,因此您需要找到其他方法。
$(document).ready(function() {
// Initiate with custom caret icon
$('select.selectpicker').selectpicker({
caretIcon: 'glyphicon glyphicon-menu-down'
});
});
body {
margin: 2em;
}
pre {
margin: 1em 0;
}
select.selectpicker {
display: none;
/* Prevent FOUC */
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.7/dist/css/bootstrap-select.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.7/dist/js/bootstrap-select.min.js"></script>
<h2>Select with Icons</h2>
<select title="Select your spell" class="selectpicker">
<option>Select...</option>
<option data-icon="glyphicon glyphicon-eye-open" data-subtext="petrification">Eye of Medusa</option>
<option data-icon="glyphicon glyphicon-fire" data-subtext="area damage">Rain of Fire</option>
</select>