繁体   English   中英

使用X关闭模态后,必须单击两次以重新打开它

[英]After closing modal using X, have to click it twice to reopen it

 //Get the modal var modal = document.getElementById('myModal'); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div style="padding: 5px;"> <a href="${pageContext.request.contextPath}/">Home</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NWHX4">NWH X4</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NWHX6">NWH X6</a> | <a href="${pageContext.request.contextPath}/ExaProd?exaType=NDCX4">NDC X4</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NDCX6">NDC X6</a> | <a href="#" data-toggle="modal" data-target="#myModal">ReadMe</a> </div> <!-- The Modal --> <div id="myModal" class="modal"> <!-- Modal content --> <div class="modal-content"> <div class="modal-header"> <span class="close">&times;</span> <h2>Exadata Capacity Read Me</h2> </div> <div class="modal-body"> <p>Some text in the Modal Body</p> <p>Some other text...</p> </div> </div> </div> 

我在其中创建了自述文件模态的代码中,如果在模态外部单击,它将关闭,并且只需单击自述链接即可重新打开它,但是如果使用“ X”关闭模态,必须单击两次自述链接才能重新打开它。
我无法弄清楚,是的,我也很新。

 .modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1050; display: none; overflow: hidden; -webkit-overflow-scrolling: touch; outline: 0; } .modal-dialog { width: 600px; margin: 30px auto; position: relative; background-color: #fff; -webkit-background-clip: padding-box; background-clip: padding-box; border: 1px solid #999; border: 1px solid rgba(0,0,0,.2); border-radius: 6px; outline: 0; -webkit-box-shadow: 0 3px 9px rgba(0,0,0,.5); box-shadow: 0 3px 9px rgba(0,0,0,.5) } .modal-body { position: relative; padding: 15px; } .modal-header { padding: 15px; border-bottom: 1px solid #e5e5e5; } .close { float: right; font-size: 21px; font-weight: 700; line-height: 1; color: #000; text-shadow: 0 1px 0 #fff; filter: alpha(opacity=20); opacity: .2; } button.close { -webkit-appearance: none; padding: 0; cursor: pointer; background: 0 0; border: 0; } 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div style="padding: 5px;"> <a href="${pageContext.request.contextPath}/">Home</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NWHX4">NWH X4</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NWHX6">NWH X6</a> | <a href="${pageContext.request.contextPath}/ExaProd?exaType=NDCX4">NDC X4</a> | <a href="${pageContext.request.contextPath}/ExaNonProd?exaType=NDCX6">NDC X6</a> | <a href="#" data-toggle="modal" data-target="#myModal">ReadMe</a> </div> <!-- The Modal --> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog" role="document"> <!-- Modal content --> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h2>Exadata Capacity Read Me</h2> </div> <div class="modal-body"> <p>Some text in the Modal Body</p> <p>Some other text...</p> </div> </div> </div> </div> 

我删除了bootstrap css,只是添加了需要模态的css。 这还不足以解决您的问题,但是您可以从此开始并进行修改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM