Bootstrap modal调用时隐藏在modal后面

Bootstrap modal hides behind the modal when it calls it

我正在使用 Bootstrap 模态,但是当我从当前模态调用第二个模态时,它隐藏在第一个模态后面。

这是我的代码和 link 到 jsfiddle

Html

<div id="dialog1" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Modal Dialog 1</h4>
      </div>
      <div class="modal-body">This is the first modal dialog</div>
      <div class="modal-footer">
        <button type="button" id="dialog-ok" class="btn btn-default">Show dialog 2</button>          
        <button type="button" id="dialog-close" class="btn btn-default" data-dismiss="modal">Close</button>          
      </div>
    </div>
  </div>
</div>

<div id="dialog2" class="modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Modal Dialog 2</h4>
      </div>
      <div class="modal-body">This is the second modal dialog</div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">OK</button>          
      </div>
    </div>
  </div>
</div>

Javascript

$("#dialog1").modal("show");

    $("#dialog-ok").on("click", function() {
        showDialog2();
    });

jsfiddle

为您的 css

中的第二个模态添加更高的 z-index
#dialog1 {
    z-index: 1999; 
}
#dialog2 {
    z-index: 2000; 
}