码迷,mamicode.com
首页 > Web开发 > 详细

对于用js获取元素的css样式属性(getComputedStyle,currentStyle,style)(getPropertyValue,getAttribute)

时间:2015-08-09 13:53:57      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

首先单独拎出来讲的是style

style: nodeObject.style.cssProperty
获取的是DOM节点上 style 属性定义的样式,如果不存在 style 属性,或者 style 属性没有定义相应的样式,则是无法获取的。
也就是说,JavaScript 不会到 <style> 标签或者 CSS 文件去获取相应的样式,只能获取 style 属性定义的样式。

就是外部样式表,内部样式表,用style都是无效的,只有内联样式是有效的,当然用style写入也是写入在内联样式的。

然后getComputedstylehe 和currentStyle都是先获取表示css样式表的对象,因为兼容IE9一下的浏览器所以IE用currentStyle,

最后考虑到兼容性,在获取css样式表对象下面的属性时,除了[ ],还多出来getPropertyVlaue,getAttribute(IE)这两个方法

最后是具体的别人博客上的链接:http://www.zhangxinxu.com/wordpress/2012/05/getcomputedstyle-js-getpropertyvalue-currentstyle/

对于用js获取元素的css样式属性(getComputedStyle,currentStyle,style)(getPropertyValue,getAttribute)

标签:

原文地址:http://www.cnblogs.com/iamwaiter/p/4714911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!