1.通过js改变元素的css样式
box原有的样式
通过js改变box的样式
点击按钮后,盒子的颜色变成黄色,注意:例如样式border-color 在js的表示是box.style.borderColor=" ";(第二个单词首字母要大写)
2.获取元素的内联样式 style(只能获取通过js改变了的css样式)
如果没有点击按钮1改变样式
点击按钮改变了样式
3.currentStyle 获取当前元素的样式(注意:在IE中能使用)
4.获取指定元素的样式(在IE8以下不能使用)
5.设置兼容
如果是普通浏览器模式computedStyle能用,否则用currentStyle
//1.
if(getComputedStyle){
return getComputedStyle(obj, null)[name];
}
else{
return obj.currentStyle[name];
}
//2.
if(obj.currentStyle){
return obj.currentStyle[name];
}
else{
return getComputedStyle(obj, null)[name];
}
//3.
return window.getComputedStyle?getComputedStyle(obj, null)[name]:obj.currentStyle[name];