gpt4 book ai didi

Javascript 交换图像

转载 作者:行者123 更新时间:2023-12-02 19:26:29 25 4
gpt4 key购买 nike

我有一张完整图像和一堆缩略图。我想用单击的任何缩略图的图像链接替换完整图像。这是代码:谢谢

function swapImage() {
var fullCoverImage = document.getElementById("full_cover");

var linkedImage = this.childNodes[0];
var thumbSource = linkedImage.getAttribute("src");

var coverSource = fullCoverImage.getAttribute("src");

var newSource = thumbSource.replace("_thumb","");
fullCoverImage.setAttribute("src", newSource);
}

<a id="slide_thumb" onClick="swapImage();" href="Javascript:void(0);"><img src="images/portfolio/fiction_001_thumb.png" /></a>
<a id="slide_thumb" onClick="swapImage();" href="Javascript:void(0);"><img src="images/portfolio/fiction_002_thumb.png" /></a>

<img id="full_cover" src="images/portfolio/fiction_001.png" />

最佳答案

这应该有效

function swapImage(aTag) {
var fullCoverImage = document.getElementById("full_cover");

var linkedImage = aTag.childNodes[0];
var thumbSource = linkedImage.getAttribute("src");

var coverSource = fullCoverImage.getAttribute("src");

var newSource = thumbSource.replace("_thumb","");
fullCoverImage.setAttribute("src", newSource);
}

<a id="slide_thumb" onClick="swapImage(this);" href="Javascript:void(0);"><img src="images/portfolio/fiction_001_thumb.png" /></a>
<a id="slide_thumb" onClick="swapImage(this);" href="Javascript:void(0);"><img src="images/portfolio/fiction_002_thumb.png" /></a>

<img id="full_cover" src="images/portfolio/fiction_001.png" />

关于Javascript 交换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11998925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com