getComputedStyle() 方法用于获取指定元素的css样式
//封装一个兼容IE的获取指定元素样式的函数`
function getPos(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];// IE
}else{
return getComputedStyle(obj)[attr]//通用
}
}
getPropertyValue() 方法返回指定的css属性的值
console.log(window.getComputedStyle(box).getPropertyValue("width")); //200px
console.log(window.getComputedStyle(box).width);
// console.log(box.currentStyle[backgroundColor]);//要在IE浏览器上试
本文介绍了如何使用getComputedStyle()函数在不同浏览器中获取元素样式,并通过getPropertyValue()方法获取指定CSS属性值。重点讲解了如何在IE浏览器中实现兼容性处理。

被折叠的 条评论
为什么被折叠?



