我有一些非常简单的 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 函数作用于两条“颜色”线。有什么建议么?