我有一些带有图像的div,当我点击这些图像时,我想要用我点击的图像打开另一个div。
JS
$('.examples img').click(function() {
var loc = $(this).attr("src");
$('#image-zoom').attr("src",loc);
});
HTML
<div class="container examples" >
<div id="image-zoom">
<img class="img-thumbnail zoom" src="" alt="dental">
</div>
<div class="row">
<div class="col-sm-12">
<img id="zoom" class="img-thumbnail zoom" src="images/01.png" alt="dental">
<img class="img-thumbnail zoom" src="images/02.png" alt="dental">
<img class="img-thumbnail zoom" src="images/03.png" alt="dental">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<img class="img-thumbnail zoom" src="images/04.png" alt="dental">
<img class="img-thumbnail zoom" src="images/05.png" alt="dental">
<img class="img-thumbnail zoom" src="images/06.png" alt="dental">
</div>
</div>
</div>
当我尝试隐藏div工作时,我认为语法错误
答案 0 :(得分:56)
更改图片的src
,而不是div:
$('#image-zoom img').attr("src",loc);
答案 1 :(得分:4)
更改第3行以引用图像而不是其容器:
$('#image-zoom img').attr("src",loc);
答案 2 :(得分:0)
#image-zoom
是div标签的ID,它没有src
属性。因此,要更改图像,您必须遍历到img
:
$('#image-zoom img').attr("src",loc);