【问题标题】:ComboBox with Filter带过滤器的组合框
【发布时间】:2014-05-02 03:59:14
【问题描述】:

我试图在选项内做一个带有过滤器的组合框

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

【问题讨论】:

  • 我正在尝试为选项选项卡上的选项插入搜索过滤器。但它只输出选项。

标签: jquery combobox filter


【解决方案1】:

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>

【讨论】:

    【解决方案2】:

    这里有完整的例子,

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多