【问题标题】:Select 2 Not working in my code选择 2 在我的代码中不起作用
【发布时间】:2014-05-08 14:30:26
【问题描述】:
<html>
<head>
    <link href="http://localhost/mytests/js/select2.css" rel="stylesheet"/>
    <script src="http://localhost/mytests/js/select2.js">
    </script>
    <script>
        $(document).ready(function()
            {
                $("#e1").select2();
                $("#e1").select2(
                    {
                        placeholder: "Select a State",
                        allowClear: true
                    });
                $("#e2_2").select2(
                    {
                        placeholder: "Select a State"
                    });
            });
    </script>
</head>
<body>
    <select id="e1">
        <option value="AL">
            Alabama
        </option>
        <option value="AL">
            Alabama
        </option>
        <option value="AL">
            Alabama
        </option>
        <option value="AL">
            Alabama
        </option>
        <option value="AL">
            Alabama
        </option>

        <option value="WY">
            Wyoming
        </option>
    </select>
</body>

上面的代码用于选择城市,也可以通过选项进行搜索。顶部的链接用于添加 select2.js 和 select2.css。这暂时不起作用。

【问题讨论】:

  • 那么,你的问题是什么?
  • 你的 javascript 控制台是否给你任何错误?
  • jquery.com上下载jQuery,在你的机器上保存到“localhost/mytests/js/jquery.js”`(把名字改成jquery.js)然后在另一个上面添加

标签: javascript jquery html jquery-select2


【解决方案1】:

这是您的代码工作 jsfiddle 。参考小提琴。 包括jquery:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<link href="http://localhost/mytests/js/select2.css" rel="stylesheet"/>
<script src="http://localhost/mytests/js/select2.js">

 $("#e1").select2();
 $("#e1").select2(
   {
     placeholder: "Select a State",
     allowClear: true
   });
 $("#e2_2").select2(
  {
    placeholder: "Select a State"
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多