【发布时间】:2018-07-12 14:10:21
【问题描述】:
当我点击一个按钮时,我有两个模态框同时出现。当我在两个模态框之外单击时,它们将同时关闭。但问题是在同时关闭 2 个模态框后发生的。页面变暗了,我无法滚动页面!
var modalA = document.getElementById('projectModalSecond2');
// Get the modal
var modal = document.getElementById('projectModal2');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
//alert(event.target)
if (event.target == modal) {
modal.style.display = "none";
modalA.style.display = "none";
}
if (event.target == modalA) {
modalA.style.display = "none";
modal.style.display = "none";
}
}
<div tabindex="0" class="modal fade pop-up-box-index pop-up-box-margin-left" id="projectModal2">
<div class="modal-dialog">
<div class="modal-content pop-up-box-top-margin pop-up-box-index">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><b>Substrate Map Station Controller (SMSC)</b></h4>
</div>
<div class="modal-body">
<img src="assets/img/gallery/ULT_SDT1.jpg" alt="" class="img-responsive">
<p>Full range of station controller.</p>
<br>
</div>
</div>
</div>
</div>
<div tabindex="0" class="modal fade pop-up-box-index pop-up-box-margin-right" id="projectModalSecond2">
<div class="modal-dialog">
<div class="modal-content pop-up-box-top-margin pop-up-box-index">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><b>Substrate Map Editor (SME)</b></h4>
</div>
<div class="modal-body">
<img src="assets/img/gallery/ULT_SDT2.jpg" alt="" class="img-responsive">
<p>Unit and Substrate map traceability</p>
<br><br>
</div>
</div>
</div>
</div>
【问题讨论】:
-
没有工作示例,很难找到问题。
-
抱歉,我正在尝试编辑它,但我似乎无法从 Dreamweaver 复制粘贴我的代码,必须输入它
-
试试https://jsfiddle.net/1cd9kmb6/1/ 这里我已经为你添加了BS 3.3.7 cdn。添加现有代码并点击“更新”。
-
感谢 jsfiddle,有用的东西。所以......我认为它是这样的? jsfiddle.net/1cd9kmb6/7
标签: javascript html css