Angbike个人博客 > Html+Css > Bootstrap模态框设置点击框以外区域不隐藏方法

Bootstrap模态框设置点击框以外区域不隐藏方法

Bootstrap模态框设置点击框以外区域不隐藏方法:

下面以button点击显示模态框为例:

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    显示模态框
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">标题</h4>
      </div>
      <div class="modal-body">
        模态框内容
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary">保存</button>
      </div>
    </div>
  </div>
</div>

以上代码触发模态框显示后,点击模态框以外区域会自动隐藏模态框,我们只需要加上以下两个属性: 刷新页面测试即可看到效果。

aria-hidden="false"
data-backdrop="static"

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="false" data-backdrop="static" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">标题</h4>
      </div>
      <div class="modal-body">
        模态框内容
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary">保存</button>
      </div>
    </div>
  </div>
</div>

博客评论已关闭