Select2 无法正确呈现
Select2 doesn't render properly
我正在尝试将 Select2 库添加到我的项目中,但失败得很惨:
我的代码如下所示:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
</head>
正文中:
<form>
<input type="hidden" name="page" value="products"/>
<div class="form-group">
<label for="exampleInputEmail1">Include</label>
<select class="form-control select2" name="inc" multiple>
<option>Chicken</option>
<option>Ready Meals</option>
<option>Rice</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Exclude</label>
<select class="form-control select2" name="exc" multiple>
<option>Chicken</option>
<option>Ready Meals</option>
<option>Rice</option>
</select>
</div>
<script type="text/javascript">
$(".select2").select2({ multiple: true});
</script>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
我做错了什么?
请检查:
在 CSS 链接
中是 "rel" 而不是 "ref"
嘿大卫,
你在 select2 中有一个愚蠢的错误,包括在你的 head 部分。您的代码中没有其他问题。
把你写
的那两行改一下
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
将ref
改为rel
即可。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
希望你遇到了这个愚蠢的错误。
我正在尝试将 Select2 库添加到我的项目中,但失败得很惨:
我的代码如下所示:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
</head>
正文中:
<form>
<input type="hidden" name="page" value="products"/>
<div class="form-group">
<label for="exampleInputEmail1">Include</label>
<select class="form-control select2" name="inc" multiple>
<option>Chicken</option>
<option>Ready Meals</option>
<option>Rice</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Exclude</label>
<select class="form-control select2" name="exc" multiple>
<option>Chicken</option>
<option>Ready Meals</option>
<option>Rice</option>
</select>
</div>
<script type="text/javascript">
$(".select2").select2({ multiple: true});
</script>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
我做错了什么?
请检查: 在 CSS 链接
中是 "rel" 而不是 "ref"嘿大卫, 你在 select2 中有一个愚蠢的错误,包括在你的 head 部分。您的代码中没有其他问题。
把你写
的那两行改一下<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link ref="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
将ref
改为rel
即可。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-css/1.4.6/select2-bootstrap.css">
希望你遇到了这个愚蠢的错误。