Jquery 引导模式对话框未显示(显示黑色背景)
我在html文件中有两个模式对话框(导致问题) 哪一个模式对话框位于html文件序列的第一位,在按钮单击时正确显示(反之亦然)。 两个模式对话框都有唯一的id,并且被适当地调用,但是一个模式对话框不会显示(如果稍后单独调用)Jquery 引导模式对话框未显示(显示黑色背景),jquery,html,bootstrap-4,bootstrap-modal,Jquery,Html,Bootstrap 4,Bootstrap Modal,我在html文件中有两个模式对话框(导致问题) 哪一个模式对话框位于html文件序列的第一位,在按钮单击时正确显示(反之亦然)。 两个模式对话框都有唯一的id,并且被适当地调用,但是一个模式对话框不会显示(如果稍后单独调用) ..... ..... 在模态对话框的调用中,我到底哪里出错了 对于相应的按钮单击,我也使用了隐藏/显示功能,但不起作用 $(“#xyzModal”).modal('hide'); $(“#abcModal”).modal('show'); 如果在打开新的模态之前需要隐
.....
.....
在模态对话框的调用中,我到底哪里出错了
对于相应的按钮单击,我也使用了隐藏/显示功能,但不起作用
$(“#xyzModal”).modal('hide');
$(“#abcModal”).modal('show');
如果在打开新的模态之前需要隐藏所有模态,那么最好的做法是:
$(".modal").modal('hide');
$("#abcModal").modal('show');
这可以确保在打开新的模态之前,所有模态都被隐藏。试试下面的代码。它正在工作。使用下面的cdn和脚本
<!DOCTYPE html>
<html>
<head>
<title>Test Modal</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#xyzModal">
Launch xyzModal modal
</button>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#abcModal">
Launch abcModal modal
</button>
<!-- Modal dialog xyz is the first in the sequence of html code -->
<div class="modal fade" id="xyzModal" tabindex="-1" role="dialog" aria-labelledby="xyzModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
.....
</div>
</div>
<!-- Modal dialog abc is the second M.D in the sequence of html code -->
<div class="modal fade" id="abcModal" tabindex="-1" role="dialog" aria-labelledby="abcModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
.....
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript">
$('#xyzModal').on('shown.bs.modal', function () {
//
})
$('#abcModal').on('shown.bs.modal', function () {
//
})
</script>
</body>
</html>
测试模态
发射XYZ模态
启动abcModal模式
.....
.....
$('#xyzModal').on('show.bs.modal',function(){
//
})
$('#abcModal').on('show.bs.modal',function(){
//
})
是的,我确实尝试过先隐藏所有模态(并显示其中一个)。这个问题仍然存在