Я работаю с учебником по модальному образу в школах W3.В уроке оно использует изображение, на которое щелкнули, как изображение, которое отображается.Я бы хотел, чтобы модал отображал файл из моего каталога, а не изображение, на которое нажали.Я планирую иметь несколько экземпляров этого мода на одной странице, которые ссылаются на отдельные файлы в каталоге.
Как получить элемент из моего каталога, а не var "img01" / "myImg"
HTML
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- The Close Button -->
<span class="close">×</span>
<!-- Modal Content (The Image) -->
<img class="modal-content" id="img01">
<!-- Modal Caption (Image Text) -->
<div id="caption"></div>
</div>
JS
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// 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";
}