如何获取 div 类 .image1
中找到的 href 链接
<div class="image1">
<a href="/images/productA.jpg"> </a>
</div>
并将其添加到图像src
此处...
<ul class="example">
<li class="GalleryImage1"> <img src="" > </li>
</ul>
最佳答案
你可以试试这个:
var href = $('.image1 a').attr('href');
//if you want the href to all img in the ul
$('.example li img').attr('src',href);
//if you want the href only to this li
$('.example .GalleryImage1 img').attr('src',href);
关于javascript - 从元素中获取 href 并添加到图像的 src 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26787819/