4
各記事に複数の画像が表示されるジャーナルがあります。彼らは自己永続化され、作られています。私は彼らのIDは何か分からない。私は最近、モーダル画像を表示するコードを追加しましたが、コードにはIDが1つしかないため、最初の画像のみがモーダル画像として表示されています。残りはすべて表示されません。最初の画像のみを表示するモーダル(コードをIDからクラスに変更する方法は?)
JavaScriptコードとhtmlをご覧ください。私にそれをどのように変更するかを教えてください。 おかげ
JSコード
// 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";
}
HTMLコード
<div class="imagewrap">
{** check if link is from galley attachments*}
{if strpos($secCont->getLink(), "/") == false}
{foreach from=$imageUrlArray key=fileName item=urlLink}
{if $fileName == $secCont->getLink()}
<img src="{$urlLink}" id="myImg" alt="{$secCont->getLabel()}" width="300" height="200">
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- The Close Button -->
<span class="close" onclick="document.getElementById('myModal').style.display='none'">×</span>
<!-- Modal Content (The Image) -->
<img class="modal-content" id="img01">
<!-- Modal Caption (Image Text) -->
<div id="caption"></div>
</div>
<a style="font:4;"><a class="imagewrap" href="{$urlLink}"><strong>[Download figure]</strong></a>
{/if}
{/foreach}
{else}
<img src="{$secCont->getLink()}">
<a style="font:4;"><a class="imagewrap" href="{$secCont->getLink()}"><strong>[Download figure]</strong></a>
{/if}
</div>
恐ろしいです。それは魅力のように働いた。 –
それからupvoteと正しい答えとして設定してください。 – Mouser
私はすでに行っていますが、私は新しいユーザーであるため公開していません –