gpt4 book ai didi

jquery - 没有显示大图 (prev() click()attr())

转载 作者:行者123 更新时间:2023-11-28 03:37:15 25 4
gpt4 key购买 nike

我使用以下代码来显示更大的图片。

<body>
<div id="Rand">
<a href="#" alt="img/groot/img1.jpg" id="unique name of picture" class="BiggerPic">
<img src="img/thumb/img1.jpg" />
</a>
<a href="#" alt="img/groot/img2.jpg" id="unique name of picture" class="BiggerPic">
<img src="img/thumb/img2.jpg" />
</a>
<a href="#" alt="img/groot/img2.jpg" id="unique name of picture" class="BiggerPic">
<img src="img/thumb/img2.jpg" />
</a>
</div>
<div id="ShowBiggerDivIMG" style="display: none;">
<img id=ShowBiggerIMG src="" />
</div>
</body>

$(document).ready(function(){
var imgScr = $('.BiggerPic').prev('a').attr('alt');
$('.ImageMagnifier').click(function(){
$('#ShowBiggerDivIMG').fadeIn(600);
$('#ShowBiggerIMG').attr('src', imgScr);
})
});

他唯一返回的是最后一张图片的最后一个链接。我如何获取事件单击缩略图的 alt(链接)以替换为 img(#ShowBiggerIMG)的 src?

最佳答案

由于要获取点击图片的alt

$(document).ready(function(){
var imgScr;
$('.BiggerPic').click(function(){
imgScr =$(this).attr('alt');
});

$('.ImageMagnifier').click(function(){
$('#ShowBiggerDivIMG').fadeIn(600);
$('#ShowBiggerIMG').attr('src', imgScr);
});
});

关于jquery - 没有显示大图 (prev() click()attr()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com