ie7及以下出错因为不支持querySelector;
ff,chrome返回颜色值rgb,ie返回white和16进制值
//getComputedStyle是一个可以获取当前元素所有最终使用的CSS属性值。返回的是一个CSS样式声明对象([object CSSStyleDeclaration]),只读。
// element.currentStyle返回的是元素当前应用的最终CSS属性值,仅ie,但此方法无法获取伪类
// getComputedStyle方法IE6~8是不支持的 ,若ie8 以下则currentStyle 否则getComputedStyle
function getCssStyleValue(elem,pseudo,attr){
var cssStyle = elem.currentStyle ? elem.currentStyle : window.getComputedStyle(elem,pseudo);
if (cssStyle.getPropertyValue) {
//ie9+及其他
return cssStyle.getPropertyValue(attr);
} else if (cssStyle.getAttribute) {
// ie6-8
return cssStyle.getAttribute(attr);
//若ie6,则属性background-color 要改为backgroundColor
}
}
console.log(getCssStyleValue(oDiv,null,"color"));
console.log(getCssStyleValue(oDiv,":after","color")); //未试过