我正在尝试为我正在设计的房地产网站实现一个弹出模式。当您进入“代理”页面时,每个代理都有自己的个人简历和“联系人”卡。选择联系人卡片时,将显示一个弹出模式,背景为灰色。我设法实现了modal,但它只适用于9数组中的第一个按钮。我知道这与唯一ID有关,但我不完全确定如何执行它。任何建议都会有所帮助。
J. 哈特
// Agent bio:
<section>
<div class="row">
<div class="column">
<div class="cardB">
<img src="https://i.imgur.com/H8By9Ns.jpg" alt="Pondra Bowen" class="center-cardB" style="width:300px;height:300px;">
<div class="container">
"Agent's personal information redacted"
<p><button id="myBtn" class="rounded">Contact</button></p>
</div>
</div>
</div>
</div>
<section>
// The modal
<div id="myModal" class="modal">
// Modal Content
<div class="modal-content">
<span class="close">×</span>
<div class="flex">
<div id="form-container">
<h3>Contact Form</h3>
<form>
<label for="name">Name</label>
<input type="text" id="name" />
<label for="email">Email</label>
<input type="text" id="email" />
<label for="subject">Subject</label>
<input type="text" id="subject" />
<label for="message">Message</label>
<textarea id="message" placeholder="Write your message here..."></textarea>
<button class="rounded">Send Message</button>
</form>
</div>
</div>
</div>
</div>
</section>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
</script>
倚天杖
相关分类