Javascript 关闭/隐藏模式时不刷新页面

Javascript 关闭/隐藏模式时不刷新页面,javascript,jquery,bootstrap-4,bootstrap-modal,Javascript,Jquery,Bootstrap 4,Bootstrap Modal,我有一个模式,点击按钮后加载。我想要的是,一旦模态被隐藏,就刷新页面。但它似乎没有像预期的那样工作,也没有看到我的错误。我的代码出了什么问题 HTML: <!DOCTYPE html> <head> <!--Libreries for modal --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.mi

我有一个模式,点击按钮后加载。我想要的是,一旦模态被隐藏,就刷新页面。但它似乎没有像预期的那样工作,也没有看到我的错误。我的代码出了什么问题

HTML:

<!DOCTYPE html>
<head>
    <!--Libreries for modal -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

</head>
<body>

    <button id="btn" onclick="openM()">Click</button>

    <div class="modal fade" id="ModalMSJ" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" style="font-weight: bold; color:black;" id="exampleModalLabel">Modal</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" style="color:black;" id="MSJ">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>                 
</body>
//refresh page when modal is hidden
$('#ModalMSJ').on('hide.bs.modal','.modal', function () {
    window.open('ModalP.php', '_self'); 
}); 

//open modal on button click
function openM() {
    $("#ModalMSJ").modal("show"); 
}

您可以尝试替换:

window.open('ModalP.php', '_self');


您可以尝试替换:

window.open('ModalP.php', '_self');


事件绑定错误,根本不调用隐藏回调。请删除第二个参数“.modal”,因为它不是必需的。最终结果:

$('#ModalMSJ').on('hide.bs.modal', function () 
{   
    window.open('ModalP.php', '_self'); 
});

事件绑定错误,根本不调用隐藏回调。请删除第二个参数“.modal”,因为它不是必需的。最终结果:

$('#ModalMSJ').on('hide.bs.modal', function () 
{   
    window.open('ModalP.php', '_self'); 
});

谢谢但它还不起作用。似乎('hide.bs.modal','.modal',function()当模态隐藏时,
$('#ModalMSJ')on('hide.bs.modal','.modal',function()
没有启动,这条评论是为我写的吗?谢谢。但是它还不起作用。
$('#ModalMSJ')on('hide.bs.modal','.modal',function()
当模态隐藏时,这条评论是为我写的吗?