jquery困境,图像替换

jquery woes , image replacement

本文关键字:替换 图像 困境 jquery      更新时间:2023-09-26

我目前正在创建一个项目,在该项目中,用户可以点击图像的缩略图,点击缩略图,替换主图像的src,以显示更大版本的缩略图。

$('.alternative_images a').click(function(e){
    var imgSrc = $(this).attr('href');
    $('.mainImage').attr('src', imgSrc);
    $('#image').attr('href', imgSrc);
    $('#image').attr('rel', $(this).attr('title'));
    e.preventDefault();
}); 

这很好,我也实现了jqZoom,但是,通过在页面上悬停较大的图像,查看缩放后的图像,总是显示相同的图像,无论您是否更改了图像,通过点击缩略图

有问题的页面是http://mensclothingroom.factoryagency.co.uk/product/ben-fogle-collection-expedition-sock/

您可能需要替换整个元素,而不仅仅是替换src属性:

$('.mainImage').replaceWith('<img src="'+imgSrc+'" class="mainImage">');