【发布时间】:2016-02-12 12:52:40
【问题描述】:
我有一个使用 PHP 代码从服务器显示在 html 中的图像列表
这是 div 中的 PHP 代码:
while($row = $result->fetch_assoc()) {
echo "<div class='col-lg-3 col-md-4 col-xs-6 thumb'><a class='thumbnail' href='#'><img id='template" . $row["imageName"]. "' class='img-responsive' src='../images/templates/" . $row["imageName"].".". $row["imageExtension"]."' alt='error' width='333px' height='262px' class='img-thumbnail' onClick='changeImage()'></a></div>";
}
PHP 代码循环服务器中的每个图像并创建另一个 div,其中包含 img。
现在,我的问题是如何识别点击的特定图片?我无法使用document.getElementById('');,因为首先我不知道 ID 对吗?虽然我通过添加 id='template" . $row["imageName"]. "' 为每个图像创建了唯一 ID,这意味着每个图像的假定 ID 是 template[x] 其中x 是数据库中的图像名称。
我正在努力如何识别用户点击的特定图像。
有什么方法可以识别图片吗?
【问题讨论】:
标签: javascript php jquery html twitter-bootstrap