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

it2025-11-13  6

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]

 

 

转载于:https://www.cnblogs.com/ruoh3kou/p/9991825.html

相关资源:数据结构—成绩单生成器
最新回复(0)