HTML:
<a id="img-1" href="https://static.example1.com/images/img1.png">
<img class="img-thumbnail" src="https://proxy.example2.com/.../img1.png">
</a>
<a id="img-2" href="https://static.example1.com/images/img2.png">
<img class="img-thumbnail" src="https://proxy.example2.com/.../img2.png"
</a>
如何获取图像的 src,但同时将两个 href 链接替换为相应的 src 链接?
试过:
var imgsrc = document.getElementsByClassName("img-thumbnail").src;
document.getElementById("img-1").src=imgsrc;
但它完全没用,尽管这是希望的。说实话,不过 xs 怎么实现呢。
在 jq 上,这是可能的。我们进入每个图像,获取其 src,并更改其父级的 href。