我正在尝试在我的python flask网页中使用bootstrap-select。以下是我目前的代码。
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css')}}" >
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-responsive.min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/sl-slide.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-select.min.css')}}">
<script src="{{ url_for('static', filename='js/jquery-3.2.1.min.js')}}" ></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-dropdown.js')}}" ></script>
<script src="{{ url_for('static', filename='js/bootstrap-select.js')}}" ></script>
</head>
<body>
<section id="about-us" class="container main">
<div class="row-fluid">
<div class="span8" >
<div class="blog">
<div class="blog-item well">
<a href="#"><h2>Heading2</h2></a>
<select class="selectpicker" id="select_county" data-live-search="true" data-style="btn-primary">
<option>County1</option>
<option>County2</option>
</select>
<select class="selectpicker" id="select_event" data-live-search="true" data-style="btn-primary">
<option>event1</option>
<option>event2</option>
</select>
<input type="submit" class="btn btn-info" value="Submit Button">
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('.selectpicker').selectpicker('refresh');
});
</script>
</body>
虽然选择作品的数据实时搜索,但选择不显示除所选项目之外的任何项目。
我甚至在$(document).ready()
刷新。我做错了什么?
答案 0 :(得分:7)
在HTML下工作正常,你的html中缺少SECTION结束/关闭,请删除document.ready的脚本。请参阅下面的HTML。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"></script>
</head>
<body>
<section id="about-us" class="container main">
<div class="row-fluid">
<div class="span8" >
<div class="blog">
<div class="blog-item well">
<a href="#"><h2>Heading2</h2></a>
<select class="selectpicker" id="select_county" data-live-search="true" data-style="btn-primary">
<option>County1</option>
<option>County2</option>
</select>
<select class="selectpicker" id="select_event" data-live-search="true" data-style="btn-primary">
<option>event1</option>
<option>event2</option>
</select>
<input type="submit" class="btn btn-info" value="Submit Button">
</div>
</div>
</div>
</div>
</section>
</body>
</html>
答案 1 :(得分:1)
在关闭<script>
标记之前移动Js文件和body
:
<body>
<script src="{{ url_for('static', filename='js/jquery-3.2.1.min.js')}}" ></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-dropdown.js')}}" ></script>
<script src="{{ url_for('static', filename='js/bootstrap-select.js')}}" ></script>
$(document).ready(function() {
$('.selectpicker').selectpicker({
style: 'btn-default',
size: false
});
});
</body>