簡體   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