每个锚点的JQuery href替换缩略图img src

JQuery for each anchor href replace thumbnail img src

本文关键字:替换 略图 img src href JQuery      更新时间:2023-09-26

别笑了,这是我尝试获取每个锚点链接href并替换.product缩略图img 的图像源的薄弱尝试

<script>
jQuery.noConflict();
jQuery(document).ready(function($) {
    //var findImage = $('dd.variation-File ul li a').attr('href');
    //get the anchor link to image
    x=$('dd.variation-File ul li a').toArray();
    //replace default thumbnail with anchor link from x
    y=$('td.product-thumbnail img').toArray();
    y.each().attr['src'].replace(this, x);
});
</script>

在我们的购物车页面上有一个显示购物车信息的表格。有多个图像(预览),如果上传了图像,那么就有一个带锚的dd.variation-File ul li,我只是想写一个脚本,如果dd.variation-File ul li a存在,用dd.variation-file ul li a 中的href替换.product-thumbnail img的img src

感谢您的帮助:)

我想你需要这个:

y.each(function(){
   $(this).attr('src',$(this).attr('src').replace(this, x));
});

但我不知道它会做什么,因为replace接受字符串而不是数组。