如何在另一个模式弹出窗口处于活动状态时关闭一个模式弹出窗口

How to close one modal popup when another one is active

我正在尝试从另一个模式弹出窗口 window 获取模式弹出窗口 window。 当我单击第一个弹出窗口 window 中的 link 时,第二个弹出窗口 window 正在打开,但第一个没有关闭。

我该怎么做?

jQuery:

 $(".get-me-license").click(function(){
    $("#license").modal('show');
 });

 $(".confirm-my-license").click(function(){
    $("#confirm-license").modal('show');
 });

HTML:

<div id="license" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                  <img class="modal-cont" src="images/license-popup.png">

                <table class="get-license-confirm"> 
                  <tr>
                    <td><a href="#" class="btn btn-warning confirm-my-license">GET LICENSE</a></td>
                  </tr>
                </table>

                </div>                
            </div>
        </div>
 </div>
 <div id="confirm-license" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                  <img class="modal-cont" src="images/license-popup.png">

                <table class="get-license-confirm"> 
                  <tr>
                    <td><a href="#" class="btn btn-warning">Confirm</a></td>
                  </tr>
                </table>

                </div>                
            </div>
        </div>
 </div>

你可以试试这两种方法

隐藏模态:

$('.YourModalElement').modal('hide');

或者完全破坏模态实例,你可以试试这个:

$('.YourModalElement').data('modal', null);

将通用 class 放在所有模态中,并在显示新模态之前使用隐藏参数调用模态函数。像这样:

假设模态的常见 class 是 "common-modal"。

$('.common-modal').modal('hide');

然后

$('yourmodal').modal();