首页 > Web开发 > 详细

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

时间:2015-08-09 13:53:56      阅读:803      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!