似乎无法让Select2运行

时间:2016-05-04 14:58:32

标签: javascript html ajax select2

我正在尝试按照他们在网站上提供的指南(https://select2.github.io/)来测试Select2。我基本上想出的是在html文件中包含URI以及允许用户选择两种状态的简单下拉菜单。但是在尝试运行时,Select2似乎根本没有实现。想知道我是否遗漏了什么?

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
  $(".js-example-basic-single").select2();
});
</script>

<select class="js-example-basic-single">
  <option value="AL">Alabama</option>
  <option value="WY">Wyoming</option>
</select>

1 个答案:

答案 0 :(得分:2)

也许是一个愚蠢的错误......你还记得包含jQuery吗?

&#13;
&#13;
$(document).ready(function() {
  $(".js-example-basic-single").select2();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>

<select class="js-example-basic-single">
  <option value="AL">Alabama</option>
  <option value="WY">Wyoming</option>
</select>
&#13;
&#13;
&#13;