2

I use the following code to show the bigger pic.

<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);
})
});

The only thing he return is the last link of the last picture. How do i get the alt (link) of the activ clicked Thumbnail to replace with the src of img(#ShowBiggerIMG)?

4

1 回答 1

0

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

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

        $('.ImageMagnifier').click(function(){
           $('#ShowBiggerDivIMG').fadeIn(600);
           $('#ShowBiggerIMG').attr('src', imgScr);
        });
    });
于 2012-11-20T09:07:15.973 回答