0

我是个菜鸟,所以请放轻松。

我试图将一个图像替换为第二个图像,同时将鼠标悬停在不同的元素上。我的问题是只有第一个图像被链接图像替换。我给每个图像一个 ID,我只是不知道如何应用它。

提前感谢您提供的任何帮助!

这是我到目前为止所拥有的:

脚本:

<script>

function changeimage(towhat,url){
if (document.images){
document.images.targetimage.src=towhat.src
gotolink=url
}
}
function warp(){
window.location=gotolink
}

</script>
<script language="JavaScript1.1">
var myimages=new Array()
var gotolink="#"

function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}


preloadimages("http://www.dxmgp.com/group/images/color_si.jpg", "http://www.dxmgp.com/group/images/bw_si.jpg","http://www.dxmgp.com/group/images/color_dxm.jpg", "http://www.dxmgp.com/group/images/bw_dxm.jpg","http://www.dxmgp.com/group/images/color_tsg.jpg", "http://www.dxmgp.com/group/images/bw_tsg.jpg","http://www.dxmgp.com/group/images/color_image.jpg", "http://www.dxmgp.com/group/images/bw_image.jpg")
</script>

HTML:

<div id="wrap">
    <div id="upper">
        <div class="u-top">
            <a href="javascript:warp()"><img src="http://www.dxmgp.com/group/images/bw_si.jpg" name="targetimage" id="si" border="0" /></a>
            <a href="javascript:warp()"><img class="picright" src="http://www.dxmgp.com/group/images/bw_dxm.jpg" name="targetimage" id="dxm" border="0" /></a>
        </div>
        <div class="u-mid">
            <img src="http://www.dxmgp.com/group/images/bw_owners.png" />
        </div>
        <div class="u-low">
            <a href="javascript:warp()"><img class="picleft" src="http://www.dxmgp.com/group/images/bw_tsg.jpg" id="tsg" /></a>
            <a href="http://www.dxmgp.com" onMouseover="changeimage(myimages[2],this.href)" onMouseout="changeimage(myimages[3],this.href)"><img class="dxmlogo" src="http://www.dxmgp.com/group/images/logo_dxm.png"  /></a>
            <a href="javascript:warp()"><img class="picright" src="http://www.dxmgp.com/group/images/bw_image.jpg" id="img" /></a>
        </div>
    </div>
    <div id="lower">
        <div class="dots"><img src="http://www.dxmgp.com/group/images/topdots.png"></div>
        <div class="logos">
            <a href="http://www.thescoutguide.com">
            <img class="picll" src="http://www.dxmgp.com/group/images/logo_tsg.png"></a>
            <a href="http://www.spatialinsights.com" onMouseover="changeimage(myimages[0],this.href)" onMouseout="changeimage(myimages[1],this.href)"><img class="picmid" src="http://www.dxmgp.com/group/images/logo_si.png"></a>
            <a href="http://www.imagebydxm.com">
            <img class="piclr" src="http://www.dxmgp.com/group/images/logo_image.png"></a>
        </div>
        <div class="dots"><img src="http://www.dxmgp.com/group/images/lowdots.png"></div>
    </div>
</div>
4

1 回答 1

2

这样的事情怎么样?考虑你有一个div包含image1.png. 当您将鼠标悬停在超链接上时,您希望将其替换image1.pngimage2.png. 然后,当您将鼠标从超链接移开时,image2.png将再次替换为image1.png

这是您div包含的图像:

<div id="image">
<img src="image1.png" />
</div>

这是超链接:

<a href="#" onmouseover="mouseOver()" onmouseout="mouseOut()">Mouse over to change image</a>

div以下是用不同图像替换内部 HTML 的 JavaScript 函数:

<script type="text/javascript">
function mouseOver() {
    document.getElementById("image").innerHTML = '<img src="image2.png" />';
}
function mouseOut() {
    document.getElementById("image").innerHTML = '<img src="image1.png" />';
}
</script>

让我知道这是否是您正在寻找的。

于 2013-11-12T19:19:01.813 回答