Fyo*_*hov 13 twitter-bootstrap
我正在使用bootstrap 2.3.2并希望实现元素看起来像下拉菜单.github中有一个解决方案:https://github.com/silviomoreto/bootstrap-select
我的代码:
<select class="selectpicker">
<option>1</option>
<option>2</option>
</select>
<script type="text/javascript">
$( function() {
$('.selectpicker').selectpicker();
})
</script>
Run Code Online (Sandbox Code Playgroud)
它不起作用.但是当我打字的时候
$('.selectpicker').selectpicker();
Run Code Online (Sandbox Code Playgroud)
在Chrome DevTools的控制台中 - 选择更改为下拉列表并且它可以正常工作.
Kam*_*ami 16
在DOM准备好之后,您需要调用初始化函数.这通常作为$(document).ready()功能块的一部分完成.
$(document).ready(function() {
$('.selectpicker').selectpicker();
});
Run Code Online (Sandbox Code Playgroud)
当您通过控制台尝试命令时,DOM已加载并可用.因此呼叫有效.上面的代码示例应该类似.
zwi*_*ion 12
1年后我遇到了同样的问题.这对我有用:
1 - 在所有者网站下载zip文件 - http://silviomoreto.github.io/bootstrap-select/
2-CSS,内部标签 - > 2files
<link rel="stylesheet" type="text/css" href="yourPath/silviomoreto-bootstrap-select-83d5a1b/dist/css/bootstrap-select.css">
<link href="yourPath/bootstrap.min.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
3-Js文件,在关闭body标签之前的末尾.
<body>
<select class="selectpicker">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
<script type="text/javascript" src="yourPath/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="yourPath/bootstrap.min.js"></script>
<script type="text/javascript" src="yourPath/silviomoreto-bootstrap-select-83d5a1b/dist/js/bootstrap-select.js"></script>
<script>
$(document).ready(function () {
$('.selectpicker').selectpicker();
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
小智 2
$(document).ready(function(){
$('.selectpicker').selectpicker({
style: 'btn-info',
size: 4
});
});
Run Code Online (Sandbox Code Playgroud)
应该可以正常工作
| 归档时间: |
|
| 查看次数: |
68779 次 |
| 最近记录: |