简体   繁体   English

仅在按“取消”按钮时如何关闭模式弹出窗口?

[英]How to close modal popup only when pressing the cancel button?

I have a simple modal and I was wondering how can I only allow the modal to be closed when clicking the "X" button or the cancel button. 我有一个简单的模态,我想知道如何仅在单击“ X”按钮或“取消”按钮时关闭模态。 Now when the user clicks outside the modal area. 现在,当用户在模态区域之外单击时。 Here's my code: 这是我的代码:

 <div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

use this.. 用这个..

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
})

or directly put it in your div 或直接放入您的div

<div id="myModal" class="modal hide" data-backdrop="static" data-keyboard="false">

在打开器按钮上使用data-backdrop="static" data-keyboard="false"将防止使用ESC关闭模式或单击背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM