首页 > 代码库 > getComputedStyle currentStyle 获取当前元素所有最终使用的CSS属性值
getComputedStyle currentStyle 获取当前元素所有最终使用的CSS属性值
object.getComputedStyle 获取当前元素所有最终使用的CSS属性值。返回的是一个CSS样式声明对象,只读,不能设置。
此方法不兼容IE8及以下,需用currentStyle方法。
function getStyle(obj.attr){ return getComputedStyle(obj)?getComputedStyle(obj)[attr]:obj.currentStyle[attr]; //判断是否有getComputedStyle方法 }
obj为需要获取属性值的对象,attr则为需要获取到的属性。使用时直接调用getStyle函数即可。注意getComputedStyle和currentStyle使用方法有区别。
getComputedStyle currentStyle 获取当前元素所有最终使用的CSS属性值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。