作者:linkstarter | 来源:互联网 | 2023-01-13 14:22
Imtryingtocreateascriptthatchangestherepeatedbackgroundimageofanelement,onthemouse
I'm trying to create a script that changes the repeated background image of an element, on the mouseover event. Unfortunately it does not work properly. I have found several possible ways to do this with Javascript but none of them has worked for me. How can I solve this problem?
我正在尝试创建一个脚本,它可以改变一个元素在mouseover事件上的重复背景图像。不幸的是,它不能正常工作。我找到了几种可能的方法来使用Javascript,但是没有一个方法对我有效。我该如何解决这个问题?
The following piece of code is not working properly:
下面这段代码不能正常工作:
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";
But if I try to use backgroundColor property, it works fine:
但是如果我尝试使用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";
3 个解决方案