如何在div内加载点击的图片

时间:2018-12-27 08:16:11

标签: php html hyperlink href

我有以下代码将随机图片加载到div中,该图片可以在Safari和Chrome中完美运行。

问题在于它不起作用。链接的href属性被错误地保留为空,我打算尝试使用target属性来实现我的目标。但是,由于我的错误,它似乎可以正常工作,我也不知道为什么。

谁能告诉我发生了什么事?

<div id="gallery">
<?php
    $imageDirectory = "./images/"; //collection of images
    $imageArray = scandir($imageDirectory); // array of filenames
    $dotFiles = array(".","..");
    $imageArray = array_diff($imageArray,$dotFiles);
    $chosenFile = rand(2,1 + count($imageArray)); ?>
    <a href=''>
    <img width="80%" class="center" src= "<? echo $imageDirectory . $imageArray[$chosenFile]?>" alt="missing image"></img>
    </a>
</div>

0 个答案:

没有答案
相关问题