javascript - How to close modal popup only when pressing the cancel button? - Stack Overflow

I have a simple modal and I was wondering how can I only allow the modal to be closed when clicking the

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. 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>

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. 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>
Share Improve this question asked Dec 29, 2016 at 8:51 user3159792user3159792 3741 gold badge9 silver badges27 bronze badges 1
  • 2 Possible duplicate of Disallow twitter bootstrap modal window from closing – Adam Azad Commented Dec 29, 2016 at 8:53
Add a ment  | 

1 Answer 1

Reset to default 3

use this..

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

or directly put it in your div

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744836635a4596301.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信