【问题标题】:No Show of bigger picture (prev() click()attr())不显示更大的图片 (prev() click()attr())
【发布时间】:2012-11-20 09:00:26
【问题描述】:

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

<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?

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    因为你想获得点击图片的alt

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

    【讨论】:

    • 这是最有帮助的!起初它返回好的,下一次单击返回第一个en而不是向右闪烁。所以我只需要从 ShowBiggerIMG 中清除 src 就可以了!
    猜你喜欢
    • 2014-10-17
    • 2014-10-19
    • 2015-07-15
    • 2013-12-21
    相关资源
    最近更新 更多