使用 jquery 插件 select2 和 bootstrap 3
Using jquery plugin select2 with bootstrap 3
我正在尝试使用 select2
,但我不能。
我在 <head>
部分使用以下代码:
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css" />
<link rel="stylesheet" type="text/css" href="select2-bootstrap.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
这是我的 HTML
和 JS
代码:
<script type="text/javascript">
$('locationMultiple').select2({
theme: "bootstrap"
});
</script>
<p>
<select class="locationMultiple form-control" multiple="multiple">
<option value="1d4h7g">Abondance (74360)</option>
<option value="lf9k9d">Alby-Sur-Cheran (74540)</option>
...
</select>
</p>
但是我的 select 拼命保持多行。
任何人都可以帮助我知道我在哪里做错了什么吗?
此代码绝对适合您...
您需要在Javascript中编写此代码:
$(document).ready(function () {
$.fn.select2.defaults.set("theme", "bootstrap");
$(".locationMultiple").select2({
width: null
})
});
我正在尝试使用 select2
,但我不能。
我在 <head>
部分使用以下代码:
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css" />
<link rel="stylesheet" type="text/css" href="select2-bootstrap.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
这是我的 HTML
和 JS
代码:
<script type="text/javascript">
$('locationMultiple').select2({
theme: "bootstrap"
});
</script>
<p>
<select class="locationMultiple form-control" multiple="multiple">
<option value="1d4h7g">Abondance (74360)</option>
<option value="lf9k9d">Alby-Sur-Cheran (74540)</option>
...
</select>
</p>
但是我的 select 拼命保持多行。
任何人都可以帮助我知道我在哪里做错了什么吗?
此代码绝对适合您...
您需要在Javascript中编写此代码:
$(document).ready(function () {
$.fn.select2.defaults.set("theme", "bootstrap");
$(".locationMultiple").select2({
width: null
})
});