Select2无法正确呈现

时间:2016-11-23 20:29:47

标签: html css twitter-bootstrap-3 select2 jquery-select2-4

我正在尝试将Select2库添加到我的项目中,但我失败了:

The rendering is all wired

我的代码如下所示:

<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>

我做错了什么?

2 个答案:

答案 0 :(得分:1)

请检查: 这是&#34; rel&#34;而不是&#34; ref&#34;在CSS链接

答案 1 :(得分:0)

Hei Dawid, 你在select2中有一个愚蠢的错误,包括在你的头部。您的代码中没有其他问题。

只需更改您编写的两行

即可

<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">

希望你有愚蠢的错误。