2015-12-28 35 views
1

我的頁面中有2個模態。當調用第二個模態時,兩者都會打開。怎麼了?使用jquery時打開2個模式

<div id="myModal" class="modal fade" role="dialog"> 
    <div class="modal-dialog"> 
     <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>Modal Body</p> 
       <button type="button" class="btn btn-default" data-dismiss="modal" href="otherpage.php">Continue</button> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default" data-dismiss="modal" href="otherpage.php">Close</button> 
      </div> 
     </div> 
    </div> 
</div>  

<div id="modal2" class="modal fade" role="dialog"> 
    <div class="modal-dialog"> 
     <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>Modal Body</p> 
       <button type="button" class="btn btn-default" data-dismiss="modal" href="otherpage.php">Continue</button> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default" data-dismiss="modal" href="otherpage.php">Close</button> 
      </div> 
     </div> 
    </div> 
</div> 

我加載引導和我使用這個函數來調用第二個模式

$('#modal2').modal('show'); 
調用這個函數的第一個模式也將顯示當

。怎麼了?因爲我希望只顯示第二個模式。

+2

根據你提供的代碼,它似乎在[這裏](https://jsfiddle.net/Lfram7hd/)工作。有沒有其他相關的代碼可能導致這種情況? –

+0

這將是一件好事,如果你也發佈了什麼情況下你打開這個'modals' –

+0

我打開提交表單時的第二個模式。爲了測試目的,我在Chrome控制檯中使用此命令:$('#modal2')。modal('show'); – mastahb

回答

1

答案由@Josh Crozier提供。

在我的custom.js中,我的代碼中還有一些依賴,下面的函數觸發了其他模式。我沒有意識到這一點。

$(window).on('shown.bs.modal', function() { 
    $('#myModal').modal('show'); 
}); 

感謝您的幫助!

相關問題