dongyuan7110 2019-05-10 15:36
浏览 335

Select2在bootstrap模式中无法正确显示

I'm trying to use select2 to display a dropdown in a modal. The dropdown isn't showing as expected, this is how it's showing below.

What it shows

If i place my Select outside of the modal, it works fine, like this

This is what should show on the modal

Here's my HTML code:

<div class='modal fade' id='comm".$row[' issue_id ']."'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title'>Add Comments</h5>
        <button type='button' class='close' data-dismiss='modal'><span>&times;</span></button>
      </div>
      <div class='modal-body'>
        <p>Add Comments to this Incident</p>
        <form method='post' action='processing.php'>
          <textarea type='text' cols='40' name='comments' required></textarea>
          <input type='hidden' name='issue_id' value='".$row[' issue_id ']."'><br>
          <input type='hidden' name='url' value='".$url."'><br>
          <select class='js-example-basic-multiple' name='tag[]' multiple='multiple'>
            <option value='AL'>Alabama</option>
            <option value='WY'>Wyoming</option>
          </select>
          <br><button type='submit' class='btn btn-primary' name='submit_comm'>Submit</button>
        </form><br>
      </div>
      <div class='modal-footer'>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('.js-example-basic-multiple').select2();
    });
</script>

</div>
  • 写回答

1条回答 默认 最新

  • duangan9251 2019-05-11 02:32
    关注

    I think you need to attach the dropdown to the modal. Try something like this:

     <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
        ...
        <select id="mySelect2">
            ...
        </select>
        ...
    </div>
    
    ...
    
    <script>
        $('#mySelect2').select2({
            dropdownParent: $('#myModal')
        });
    </script>
    

    I got this from here: https://select2.org/troubleshooting/common-problems

    Please read the article above for more information about this problem !

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?