【问题标题】:When Using select2 , select box hide automatically使用 select2 时,选择框自动隐藏
【发布时间】:2019-01-19 11:38:45
【问题描述】:
<div class="col-12 col-sm-12 col-md-5 col-lg-5 col-xl-5" id="old_customer" style="display: block;>
    <label for="customersID" class="control-label">Customer </label>
    <select name="customersID"  id="customersID" onchange="getCustomersDue()"  >
        <option value="">Select Customer </option>
        <?php
        foreach($customers as $p)
        {
            $selected = ($p['customersID'] == $this->input->post('customersID')) ? ' selected="selected"' : "";

            echo '<option value="'.$p['customersID'].'" '.$selected.'>'.$p['name']."-".$p['mobile'].'</option>';
        }
        ?>
    </select>

 $("#customersID").select2();

我正在从数据库中获取所有客户,并使用 select2 搜索并选择项目。但是当我选择某些东西时,整个 div 会隐藏,我无法重新选择任何东西。但该值仍保留在页面中。任何解决方案都会有所帮助。谢谢。

【问题讨论】:

    标签: php jquery jquery-select2


    【解决方案1】:

    您需要使用下面的代码进行 onchange。删除此代码onchange="getCustomersDue()"

    $('#customersID').on('select2:select', function(e) {
        console.log('Selecting: ' , e.params.args.data);
    });
    

    阅读本文

    https://select2.org/programmatic-control/events

    【讨论】:

    • 还是有同样的问题。 @Vel
    • 请创建一个小提琴
    猜你喜欢
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多