可以在引导中关闭静态模式

Possible to get a static modal to close in bootstrap?

本文关键字:静态 模式      更新时间:2023-09-26

我们有一个页面,客户端希望模态在页面视图中可见。 我遇到了引导模式不会关闭的问题,除非您手动启动它

我做错了什么吗? 如果单击启动模式(即使模式已经可见),则可以将其关闭

这是 HTML:

<a class="btn" data-toggle="modal" href="#myModal">Launch Modal</a>
<div class="modal" id="myModal">
  <div class="modal-header">
    <button class="close" data-dismiss="modal" data-target="#myModal">&times;</button>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal" data-target="#myModal">Close</a>
    <a href="#" class="btn btn-primary">Save changes</a>
  </div>
</div>​

CSS只是Bootstap的东西。我们根本没有为此使用任何JavaScript代码。

jsFiddle 上的实时复制

你不是在"启动"模态,你只是有可见的内联标记。模态根本没有真正打开。

隐藏模态(将style="display: none"添加到#myModal div),然后使用ready中的.modal('show')触发打开它:

jQuery(function($) {
    $('#myModal').modal('show');​​
});

更新的小提琴

这将连接关闭按钮所需的处理程序,正确定位它,进行背景覆盖等。