我有一些非常简单的javascript构建,可以在Chrome中正常运行。但是,有一些东西在IE和Firefox中无效。这是代码:
function updateColors(){
ChangeCSSRule('background-color',color,2);
ChangeCSSRule('color',textcolor,0);
ChangeCSSRule('color',textcolor,1);
ChangeCSSRule('background-image','url(borders/r_edge_'+imgcolor+'.png)',3);
ChangeCSSRule('background-image','url(borders/l_edge_'+imgcolor+'.png)',4);
ChangeCSSRule('background-image','url(borders/t_edge_'+imgcolor+'.png)',5);
ChangeCSSRule('background-image','url(borders/b_edge_'+imgcolor+'.png)',6);
}
function ChangeCSSRule(xElement, xValue, value){
var strCSS = 'cssRules';
if(document.all){
strCSS = 'rules';
}
document.styleSheets[0][strCSS][value].style[xElement] = xValue;
}
这是样式表:
.firstName {
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
margin: 0px;
}
.lastName {
font-family: Verdana, Geneva, sans-serif;
font-size: 25px;
text-wrap: none;
margin: 0px;
}
.bg {
background-color: #ffffff;
}
.r_edge {
background-image: url(borders/r_edge_white.png);
background-repeat: repeat-y;
}
.l_edge {
background-image: url(borders/l_edge_white.png);
background-repeat: repeat-y;
}
.t_edge {
background-image: url(borders/t_edge_white.png);
background-repeat: repeat-x;
}
.b_edge {
background-image: url(borders/b_edge_white.png);
background-repeat: repeat-x;
}
.right {
text-align: right;
}
我在几行无效的旁边放了星号。奇怪的是,ChangeCSSRule函数适用于两条“颜色”线。有什么建议吗?
答案 0 :(得分:5)
在javascript中更改CSS属性时,你需要使用它们,例如:background-color变为backgroundColor,background-image变为backgroundImage。