Javascript中style,currentStyle和getComputedStyle的区别以及获取css操作方法

style: 只能获取行内style。

   调用:obj.style.属性;

   兼容:都兼容

currentStyle: 可以获取该obj所有style,但只可读

   调用:obj.currentStyle["属性"] 或者 obj.currentStyle.属性;

   兼容:只兼容IE,不兼容火狐和谷歌

getComputedStyle: 可以获取该obj所有style,但只可读。

   调用:getComputedStyle(obj,null)[属性] 或者 getComputedStyle(obj,null).属性;

   兼容:只兼容火狐和谷歌,不兼容IE

个人常用写法:

return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr]

 

 


posted @ 2018-11-20 21:40  Ruohua3kou  阅读(287)  评论(0编辑  收藏  举报