2016-12-29 179 views
0

我有一個簡單的模式,我想知道如何才能讓模式被關閉,當點擊「X」按鈕或取消按鈕。現在當用戶在模態區域外單擊時。 這裏是我的代碼:如何僅在按下取消按鈕時關閉模式彈出窗口?

<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> 
+2

[Disallow twitter bootstrap modal window from closing]可能出現重複(http://stackoverflow.com/questions/9894339/disallow-twitter-bootstrap-modal-window-from-closing) –

回答

2

使用這個..

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

,或者直接把它放在你的div

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

上機按鈕使用data-backdrop="static" data-keyboard="false"將防止ESC或關閉模式點擊背景。

相關問題