Вопрос

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

the above code is for selecting cities and also being able to search through the options. The link at the top is for adding select2.js and select2.css. this is not working at the moment.

Это было полезно?

Решение

here is your code working jsfiddle .Refer the fiddle. Include 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"
 });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top