IE currentStyle && getComputedStyle

用document.getElementById(‘element').style.xxx可以获取元素的样式信息,

可是它获取的只是DOM元素style属性里的样式规则,对于通过class属性引用的外部样式表就获取不到了


IE可以识别 currentStyle ,其他浏览器可以识别 getComputedStyle :

function getStyle(obj, attr) 

if(obj.currentStyle) 

return obj.currentStyle[attr]; 

else 

return getComputedStyle(obj,null)[attr]; 



/*
document.defaultView.getComputedStyle (jQuery)

也可以先 获取样式,然后,IE浏览器 :getAttribute其他 getPropertyValue获取属性值
oStyle = obj.currentStyle? obj.currentStyle : window.getComputedStyle(obj, null);
if (oStyle.getPropertyValue) { alert("getPropertyValue下背景色:" + oStyle.getPropertyValue("background-color")); } else { alert("getAttribute下背景色:" + oStyle.getAttribute("backgroundColor")); }
*/

 

转载于:https://www.cnblogs.com/xinfangzhang/p/7723208.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值