簡體   English   中英

模態框不顯示

[英]Modal Box not showing

我正在嘗試在網站上制作一個模態框,但它沒有顯示出來。模態框中的內容很好,但如果可能需要,我還會在這里附上內容的 CSS 代碼。

 document.getElementById('buttonL').addEventListener("click", function() { document.querySelector('.bg-modal').style.display = "flex"; }); document.querySelector('.close').addEventListener("click", function() { document.querySelector('.bg-modal').style.display = "none"; });
 .bg-modal{ background-color: rgba(0, 0, 0, 0.5); width: 100%; height: 100%; position: fixed; display: none; justify-content: center; align-items: center; bottom: 0px; } .modal-content{ width: 600px; height: 300px; background-color: white; opacity: 1; border-radius: 2px; } .modal-content h1{ align-items: center; text-align: center; margin-top: 40px; font-family: 'Rubik', sans-serif; } .modal-content img{ float: left; width: 160px; margin-top: 20px; margin-left: 60px; } .modal-content p{ float: right; margin-top: 20px; margin-right: 60px; font-size: 16px; } .close { position: relative; float: right; margin-right: 8px; font-size: 32px; color: #333; background-color: none; cursor: pointer; }
 <button id="buttonL" class="buttonLegal">LEGAL DETAILS</button> <div class="bg-modal"> <div class="modal-content"> <div class="close">✖</div> <h1>LEGAL DETAILS</h1> <img src="someimagehere.jpg"> <p>some text here</p> </div> </div>

我搜索了整個互聯網並嘗試了很多方法,但仍然無法顯示模態框。 我想我的 Javascript 代碼可能有錯誤,但我不確定。 所以,我希望你能在這件事上幫助我。 謝謝!

您可以從https://www.w3schools.com/嘗試這個簡單的模態代碼

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <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.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM