模态内容不显示在下拉列表中

Posted

技术标签:

【中文标题】模态内容不显示在下拉列表中【英文标题】:Modal content don't show in dropdown 【发布时间】:2021-10-31 17:08:08 【问题描述】:

我正在从下拉列表中调用 Bootstrap 5 模式,但它没有显示内容,而是仅显示灰色背景。我错过了什么?

这里是jsfiddle,这里是代码:

<div class="container">
  <div class="row">
    <div class="inline-block">
      <div class="dropdown">
        <button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="btn btn-primary">Dropdown</button>
        <ul class="dropdown-menu dropdown-menu-end">
          <li>
            <button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#test">
              Launch demo modal
            </button>

            <div class="modal fade" id="test" tabindex="-1">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title">Modal title</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body">
                    ...
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                  </div>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

【参考方案1】:

模态代码应该在&lt;ul&gt;标签之外

<div class="container">
  <div class="row">
    <div class="inline-block">
      <div class="dropdown">
        <button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="btn btn-primary">Dropdown</button>
        <ul class="dropdown-menu dropdown-menu-end">
          <li>
            <button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#test">
                Launch demo modal
              </button>

          </li>
        </ul>
      </div>
    </div>
  </div>

  <div class="modal fade" id="test" tabindex="-1">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">Modal title</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          ...
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
        </div>
      </div>
    </div>
  </div>
</div>

【讨论】:

谢谢,我还以为是什么傻事。

以上是关于模态内容不显示在下拉列表中的主要内容,如果未能解决你的问题,请参考以下文章

下拉列表不显示内容但白色空白 XSLT

如何在 jquery 中重置下拉列表以便没有选择任何内容?

MFC中怎样实现组合框显示下拉列表啊?

更改下拉列表打开数据模式

到达下拉列表时单击iphone移动箭头键,应显示下拉列表内容

下拉列表内容怎么设置?