带过滤器的ComboBox

时间:2014-05-02 03:59:15

标签: jquery combobox filter

我试图在选项

中使用过滤器进行组合框
<head>
<link href="select2.css" rel="stylesheet"/>
<script src="select2.js"></script>
<script>
$(document).ready(function() { $("#e1").select2(); });
</script>
</head>
<body>
<select id="e1">
<option value="AL">Alabama</option>
...
<option value="WY">Wyoming</option>
</select>
</body>

我提到使用此链接作为指南(http://ivaynberg.github.io/select2/),但似乎第一个指南只有带标签的下拉菜单,搜索过滤器不会显示。我对使用它很困惑,因为这是我第一次使用github。

2 个答案:

答案 0 :(得分:0)

select2.js不是一个库而是一个插件,而jQuery的插件可以让你需要包含jQuery库

<head>
<link href="select2.css" rel="stylesheet"/>
<!--here you need to put the library, for eg: I'm including cdn version of jQuery 1.10.2-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="select2.js"></script>
<script>
$(document).ready(function() { $("#e1").select2(); });
</script>
</head>

答案 1 :(得分:0)

这里有完整的例子,

Demo

<head>
    <link href="http://ivaynberg.github.io/select2/select2-3.4.8/select2.css?ts=2014-05-01T06%3A52%3A24-07%3A00" rel="stylesheet"/>
  <link href="http://ivaynberg.github.io/select2/bootstrap/css/bootstrap.css" rel="stylesheet"/>
  <script src="http://ivaynberg.github.io/select2/js/jquery-1.7.1.min.js"></script>
    <script src="http://ivaynberg.github.io/select2/bootstrap/js/bootstrap.min.js"></script>

<script src="http://ivaynberg.github.io/select2/select2-3.4.8/select2.js?ts=2014-05-01T06%3A52%3A24-07%3A00"></script>
    <script>
        $(document).ready(function() { $("#e1").select2(); });
    </script>
</head>
<body>
    <select id="e1">
        <option value="AL">Alabama</option>
        ...
        <option value="WY">Wyoming</option>
    </select>
</body>