我有一些代码可以在鼠标悬停时放大图像:
<script>
function bigImg(x)
{
x.style.height="70px";
x.style.width="237px";
}
function normalImg(x)
{
x.style.height="56px";
x.style.width="218px";
}
</script>
我用以下方法调用这些函数:
<a><img border="0" src="category_icons/addorder.png" onmouseover="bigImg(this)" onmouseout="normalImg(this)"></a>
但我真正想做的是让 bigIMG(x)
函数也改变图像。我对 javascript 不是很熟悉,想知道是否有人知道我可以编写什么代码来交换图像。图像名称是 addorder2.png。我试过使用 this.src="addorder2.png";但这不起作用。
最佳答案
这样就可以了。将图像 src 更改为“addorder2.png”。
<script>
function bigImg(x)
{
x.style.height="70px";
x.style.width="237px";
x.src = "addorder2.png";
}
function normalImg(x)
{
x.style.height="56px";
x.style.width="218px";
x.src = " addorder.png";
}
</script>
关于Javascript onMouseover 交换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21861854/