1

我有以下代码通过将鼠标悬停在拇指图像上来更改全尺寸图像 -

<script type="text/javascript">
    $('.thumbimage a img').on('hover',function(){
            $('.fullsizeimage a img').attr('src',$(this).attr('src'));
        });
</script>

如何设置它以使其仅更改其上方的全尺寸图像以及所有其他全尺寸图像?

我尝试了以下没有运气:

 <script type="text/javascript">
        $('.thumbimage a img').on('hover',function(){
            $('.thumbimage a img').prev('.fullsizeimage a img').attr('src',$(this).attr('src'));
        });
        </script>

http://jsfiddle.net/CUZBa/19/

4

2 回答 2

1

看起来像是row一个父元素。

$('.thumbimage a img').on('click hover', function() {
    $(this).parents('.row').find('.fullsizeimage img').attr('src', $(this).attr('src'));
});​
于 2012-10-31T21:07:33.580 回答
0

.prev()将遍历元素的兄弟姐妹而不是其祖先..

您可以.closest()在这种情况下使用

尝试这个

$('.thumbimage a img').on('click hover', function() {
    $(this).closest('.row').find('.fullsizeimage img').attr('src', $(this).attr('src'));
});​
于 2012-10-31T21:13:22.397 回答