2011-05-30 83 views
0

我有一个关于JavaScript的问题,有一个大的图片和缩略图,我的JavaScript函数改变了从缩略图中获取它的大图的链接,它工作正常,但我也有高速滑行,适用于大图片,当点击大图片时,其实际大小显示为高速滑动,但我有一个小问题,当我更改大图片的链接时,它会自动将此图片的两个链接,一个在大画面和其他在缩略图,所以我需要删除在缩略图的其他链接后,我一下就可以了,所以这是我的脚本现在:删除重复的链接

$(document).ready(function() { 
    $('.image').click(function(event) { 
    event.preventDefault(); 
    var imagePath = $(this).attr("href"); 
    var newImg = new Image; 
    newImg.onload = function(){ 
     $('#big_picture2').hide(); 
     $('#big_picture2').attr('src', imagePath); 
     $('.product_image_large').attr('href', imagePath); 
     $('#big_picture2').fadeIn('slow'); 
    }; 
    newImg.src = imagePath; 
    }); 
}); 
+1

由于您似乎正在使用jQuery,因此我添加了该标记(替换“重复”),因此,专注于jQuery而不是JavaScript的人会看到它。 – 2011-05-30 08:13:32

+0

你的问题或问题是什么? – reporter 2011-05-30 08:13:49

+0

@reporter我想删除缩略图中的重复链接,因为我使用highslide,图片的高速滑动将重复 – user775917 2011-05-30 08:16:32

回答

0

未经测试,但认为这应该工作:

$(document).ready(function() { 
    $('.image').click(function(event) { 
    event.preventDefault(); 
//add big picture link to active thumbnail 
$('.image.active').attr('href',$('#big_picture2').attr('src')).removeClass('active'); 
//set new active thumbnail 
$(this).addClass('.active'); 
    var imagePath = $(this).attr("href"); 
//remove this href 
$(this).removeAttr('href'); 
    var newImg = new Image; 
    newImg.onload = function(){ 
        $('#big_picture2').hide(); 
        $('#big_picture2').attr('src', imagePath); 
        $('.product_image_large').attr('href', imagePath); 
        $('#big_picture2').fadeIn('slow'); 
    }; 
    newImg.src = imagePath; 
    }); 
});