js中style、currentStyle、getComputed、runtimeStyle的区别
2014-03-30 14:53
381 查看
1、obj.style只能获得内嵌样式(inline Style)就是写在Tag里面的,他访问不到那些链接的外部css和在head中用<style>声明的style。
所以必须认识到在那些使用外部Css文件的页面中,如果用style赋值,如obj.style=“color:yellow”;显然效果是正确的,其中的奥秘确是只是在该对象的tag上多添加了一个style属性,按照由小到大的优先级呈现罢了。
2、obj.currentStyle就强大多了,他能够获取关于这个节点所有位置的style,但是他也按照优先级,说穿了就是显示的是什么他就是指向哪一个style,如下代码字体优先是显示blue的,那currentStyle.color就是blue,当然此时style.color也会是blue,但只限于IE。
3、要兼容FF,就得需要getComputedStyle 出马了 注意:getComputedStyle是firefox中的,
document.defaultView.getComputedStyle(mydiv,null).width
window.getComputedStyle(mydiv , null).width
4、runtimeStyle简单的说就是你可以对一个节点的行内样式样式赋值,他将成为最高优先级的节点样式。
所以必须认识到在那些使用外部Css文件的页面中,如果用style赋值,如obj.style=“color:yellow”;显然效果是正确的,其中的奥秘确是只是在该对象的tag上多添加了一个style属性,按照由小到大的优先级呈现罢了。
2、obj.currentStyle就强大多了,他能够获取关于这个节点所有位置的style,但是他也按照优先级,说穿了就是显示的是什么他就是指向哪一个style,如下代码字体优先是显示blue的,那currentStyle.color就是blue,当然此时style.color也会是blue,但只限于IE。
3、要兼容FF,就得需要getComputedStyle 出马了 注意:getComputedStyle是firefox中的,
document.defaultView.getComputedStyle(mydiv,null).width
window.getComputedStyle(mydiv , null).width
4、runtimeStyle简单的说就是你可以对一个节点的行内样式样式赋值,他将成为最高优先级的节点样式。
相关文章推荐
- currentStyle、runtimeStyle、getComputedStyle的区别
- js中style,currentStyle和getComputedStyle的区别以及获取css操作方法
- js便签笔记(7)——style、currentStyle、getComputedStyle区别介绍【转载】
- js便签笔记(7)——style、currentStyle、getComputedStyle区别介绍【转载】
- js中获取元素属性、currentStyle与getComputedStyle的区别
- js中style,currentStyle,getComputedStyle和getBoundingClientRect的区别以及获取css操作方法
- JS中style、currentStyle、getComputedStyle的区别
- style,currentStyle,runtimeStyle,getComputedStyle的区别及用法
- JS中style、currentStyle、getComputedStyle的区别
- js中style,currentStyle和getComputedStyle的区别
- js中style,currentStyle和getComputedStyle的区别
- style,currentStyle,runtimeStyle,getComputedStyle的区别及用法
- js中style,currentStyle和getComputedStyle的区别
- Js中的style,currentStyle,getComputedStyle()区别
- Js中的style,currentStyle,getComputedStyle()区别
- style、currentStyle、getComputedStyle区别介绍
- js获取样式、currentStyle和getComputedStyle的兼容写法
- style,currentStyle,getComputedStyle的区别和用法
- js中关于style,currenStyle,和getComputedStyle的区别
- style、currentStyle、getComputedStyle的区别和用法