首页 > 其他 > 详细

getComputedStyle与currentStyle获取样式(style/class)

时间:2017-04-24 11:47:10      阅读:180      评论:0      收藏:0      [点我收藏+]

用document.getElementById(‘element‘).style.xxx获取行内样式

window.getComputedStyle(element,null).color返回的是一个样式对象,有很多值。可以获取外联CSS样式和行内样式,但是它不兼容IE,而且是只读的,不能设置样式

element.currentStyle.color是IE的写法

所以可以写成:

return window.getComputedStyle ? window.getComputedStyle(obj,null).color : obj.currentStyle.color; 

color它返回的是rgb(255,255,255) 

 

jquery的css()方法就是用了document.defaultView.getComputedStyle相当于window.getComputedStyle

写成这样是为了兼容FF :当使用Firefox 3.6时,其frame中需要使用document.defaultView去获取window对象,才能使用其getComputedStyle方法

getComputedStyle与currentStyle获取样式(style/class)

原文:http://www.cnblogs.com/t1amo/p/6755227.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!