javascript - 在多个模态中使用缩略图前一个模态缩略图显示到下一个模态
问题描述
非常感谢任何帮助,我找不到任何解决方案,而且我很讨厌 js
<script>
function myFunction(imgs) {
var expandImg = document.getElementById("expandedImg");
expandImg.src = imgs.src;
expandImg.parentElement.style.display = "block";
<!-- I Thought maybe I would have to make a new var for each modal which isn't ideal -->
<!-- But was the only way I could figure out how to get multiple modals working with thumbnails -->
var expandImg1 = document.getElementById("expandedImg1");
expandImg1.src = imgs.src;
expandImg1.parentElement.style.display = "block";
}
</script>
//Modal 1 dialog
<img id="expandedImg" style="width:80%" src="img1.jpg">
<div class="col-md-2 product_img">
<img src="img1.jpg" style="width:120px" onclick="myFunction(this);">
<img src="img2.jpg" style="width:120px" onclick="myFunction(this);">
</div>
//Modal 2 dialog
<img id="expandedImg1" style="width:80%" src="img1.jpg">
<div class="col-md-2 product_img">
<img src="img3.jpg" style="width:120px" onclick="myFunction(this);">
<img src="img4.jpg" style="width:120px" onclick="myFunction(this);">
</div>
Feels like it's probably something really dumb I overlooked or don't know yet but any help would be greatly appreciated
解决方案
我发现了我的问题,很抱歉我错过了一些重要的代码
<input type="button" value="Quick View" src="img/jesus.jpg" class="viewbtn btn btn-
primary" data-toggle="modal" data-target="#product_view7" onclick="myFunction(this);">
问题是我有使用的按钮标签而不是上面显示的输入
推荐阅读
- keycloak - 无法执行 Keycloak 单次注销
- bash - 确保主机和 Docker 容器中的用户名和用户 ID 相同
- sql - 在 BigQuery 中按天对所有读数进行分组
- database - 在 Microsoft Access 中另一个文本字段更改值后立即重新查询文本字段
- python - 无法连接到具有 unicode 名称的数据库
- java - 具有自定义的每个公司文件系统的 SSHD 服务器的 MDC 日志记录
- sql - SQL Select Where Order by 在同一个函数上
- javascript - 在 JavaScript 和 Jquery 中管理登录凭据的最佳方法?
- java - 如何在具有特定范围的间隔上创建间隔
- python - 删除实例时触发 Django post_save() 信号