学校のプロジェクトでは、私のクラスのすべての生徒にモーダルを作成したいと思います。私の問題は、最初のモーダルしか働いていないことです。あなたのコードから模型をコピーする方法
// 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";
}
// 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";
}
}
/* The Modal (background) */
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 14% auto;
/* 15% from the top and centered */
padding: 20px;
border: none;
width: 80%;
/* Could be more or less, depending on screen size */
box-shadow: 0 10px 20px 0px rgba(0, 0, 0, 0.5);
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
/* Button Design */
#myBtn {
background-image: url(/images/blank-profile-picture-973460_960_720.png);
font-family: Lato-Bold;
font-size: 20px;
background-color: rgb(55, 154, 177);
background-size: cover;
width: 300px;
height: 300px;
margin: 10px;
float: left;
text-align: center;
color: white;
border: 0;
cursor: pointer;
}
p.Info {
font-family: Lato-regular;
font-size: 15px;
color: rgb(40, 40, 40);
}
<!-- Trigger/Open The Modal -->
<button id="myBtn">Anthony</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p class="Info">
Nachname:König<br> Vorname:Anthony
<br> Geburtstag:24.12.1998
<br> Herkunft:Deutschland
<br> Adresse:xxxxxxxxxxxxxxxxx
<br> Mobilnummer:xxxxxxxxxxxxxx
<br> E-Mail:xxxxxxxxxxxxxxxxxbr> Fachlicher Schwerpunkt:Programmieren<br> Hobbys:Basketball, Tennis, Krafttraining, Gaming und Fussball.<br> Socialmedia:url Facebook: url Instagram:<br> Snapcode: anthony.k1ng<br>
</p>
</div>
</div>
<!-- Trigger/Open The Modal -->
<button id="myBtn">David</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p class="Info">
Nachname:König<br> Vorname:Anthony
<br> Geburtstag:24.12.1998
<br> Herkunft:Deutschland
<br> Adresse:xxxxxxxxxxxxxxxxxxxxxx
<br> Mobilnummer:xxxxxxxxxxxxxxxxxx
<br> E-Mail:xxxxxxxxxxxxxxxx
<br> Fachlicher Schwerpunkt:Programmieren<br> Hobbys:Basketball, Tennis, Krafttraining, Gaming und Fussball.<br> Socialmedia:url Facebook: url Instagram:<br> Snapcode: anthony.k1ng<br>
</p>
</div>
</div>
私は、CSS/JavaScriptのaswellで何かを変更する必要がありますか? –
@SphexOw ... jsのフィドルでコードを更新してもいいですか? – UniQue
@UniQue確かに:)すごくいいですか、今すぐ自分で試してみてください! –