简体   繁体   English

Select2 正在复制我的下拉列表

[英]Select2 is duplicating my dropdown list

Select2 is duplicating my dropdown list so I have both the original select list and also the select2 select box, I have been unable to recreate it outside of my project so it could be an import perhaps, has anybody experienced anything similar before or know what imports could be causing it? Select2 正在复制我的下拉列表,所以我有原始选择列表和 select2 选择框,我无法在我的项目之外重新创建它,所以它可能是一个导入,有没有人以前经历过类似的事情或知道什么导入可能导致它? The only information I could find was on jquery growfield which I do not have.我能找到的唯一信息是关于 jquery growfield 的,我没有。 Thanks!谢谢!

HTML HTML

<p class="form-control input-lg"><label for="industry">Industry</label>:
    <select class="industry" id="industry" name="industry">
        <option value="Select" selected="selected"></option>
        {% for industry in industries %}
            <option value="{{ industry }}">{{ industry }}</option>
        {% endfor %}
    </select>
</p>

JQuery查询

 <script type="text/javascript">
     $(document).ready(function () {
     $("#industry").select2();
     $
 });

I found out that the issue was caused by my use of css on the original list element.我发现问题是由我在原始列表元素上使用 css 引起的。
Select2 works by applying the class select2-hidden-accessible to the actual select field I wrote. Select2通过将类select2-hidden-accessible应用于我编写的实际选择字段来工作。

That class has CSS that, among other things, shrinks the original select field to 1px width so it is not visible.该类具有 CSS,除其他外,它将原始选择字段缩小到 1px 宽度,因此它不可见。
Then it renders its own span classes that have the select2 functionality based on the content from the original select element.然后它根据原始 select 元素的内容呈现具有select2功能的自己的span类。

CSS on .form_inputs select{} was overriding this shrinking to 1px width . .form_inputs select{}上的 CSS 覆盖了这个缩小到1px width

It's old but always useful !它很旧但总是有用的!

I forgot to import the CSS for select2... That was why it didn't work and displayed the select twice.我忘了为 select2 导入 CSS ......这就是为什么它不起作用并显示两次选择。

I hope it'll be helpful !我希望它会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM