【发布时间】:2009-12-15 11:14:33
【问题描述】:
我正在尝试创建一个脚本,在鼠标悬停事件上更改元素的重复背景图像。不幸的是,它不能正常工作。我已经找到了几种可能的方法来使用 JavaScript 做到这一点,但没有一个对我有用。我该如何解决这个问题?
以下代码不能正常工作:
while (document.getElementById("content_" + modid + "_" + i) != null) {
document.getElementById("content_" + modid + "_" + i).style.display = "none";
document.getElementById("menu_" + modid + "_" + i).style.backgroundImage = "url(psycho_normal.jpg)";
document.getElementById("menu_" + modid + "_" + i).style.backgroundPosition = "top left";
document.getElementById("menu_" + modid + "_" + i).style.backgroundRepeat = "repeat-x";
i++;
}
document.getElementById("menu_" + modid + "_" + ind).style.backgroundImage = "url(phycho_hover.jpg)";
document.getElementById("menu_" + modid + "_" + ind).style.backgroundPosition = "top left";
document.getElementById("menu_" + modid + "_" + ind).style.backgroundRepeat = "repeat-x";
但如果我尝试使用 backgroundColor 属性,它可以正常工作:
while (document.getElementById("content_" + modid + "_" + i) != null) {
document.getElementById("content_" + modid + "_" + i).style.display = "none";
document.getElementById("menu_" + modid + "_" + i).style.backgroundColor = "#000000";
i++;
}
document.getElementById("menu_" + modid + "_" + ind).style.backgroundColor = "#ff0000";
【问题讨论】:
-
您确定文件名为
phycho_hover.jpg?好像打错了 -
是的,图片的名称是正确的。
-
也许您可以发布更多代码?您的内容和菜单项在 HTML 中的外观如何?如何调用 onmouseover 代码?
标签: javascript image background repeat