1、obj.style只能获得内嵌样式(inline Style)就是写在Tag里面的,他访问不到那些链接的外部css和在head中用<style>声明的style。 所以必须认识到在那些使用外部Css文件的页面中,如果用style赋值,如obj.style=“color:red”;显然效果是正确的,其中的奥秘确是只是在该对象的tag上多添加了一个style属性,按照由小到大的优先级呈现罢了。 2、obj.currentStyle就强大多了,他能够获取关于这个节点所有位置的style,但是他也按照优先级,说穿了就是显示的是什么他就是指向哪一个style,如下代码字体优先是显示blue的,那currentStyle.color就是blue,当然此时style.color也会是blue。 复制代码 代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>testStyle</title> <style> .lala{ color:yellow; } </style> </head> <body> <div id="tt" style="color:blue;" class="lala">1111</div> </body> <script> alert(document.getElementById("tt").currentStyle.color); </script> </html> 若去掉以上<div>中的style为<div id="tt" class="lala">1111</div>,那么currentStyle.color就根据优先级变成了yellow,但是此时style.color为空。 3、runtimeStyle简单的说就是你可以对一个节点的样式赋值,他将成为最高优先级的节点样式。 如: 复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style> .lala{ color:yellow; }</style> </head> <body> <div id="tt" style="color:blue;" class="lala">1111</div> </body> <script> document.getElementById("tt").runtimeStyle.color="black"; alert(document.getElementById("tt").currentStyle.color); alert(document.getElementById("tt").runtimeStyle.color); alert(document.getElementById("tt").style.color); </script> </html> 此时页面显示字的颜色是runtimeStyle赋值后的black。但是只有currentStyle.color和runtimeStyle本身能够取到这个值,style.color取到的依然是tag中的blue。
相关推荐
style、 currentStyle、 runtimeStyle区别分析,需要的朋友可以参考下。
JavaScript style对象与CurrentStyle对象案例详解 1、Style对象 style对象代表一个单独的样式声明,可以从应用样式的文档元素访问Style对象。style对象获取的是内联样式,即元素标签中style属性的值。 例子: ...
主要介绍了前端学习笔记style,currentStyle,getComputedStyle的用法与区别,需要的朋友可以参考下
(currentStyle)javascript为何有时用style得不到已设定的CSS的属性
最常用的是style属性,在JavaScript中,通过document.getElementById(id).style.XXX就可以获取到XXX的值,但意外的是,这样做只能取到通过内嵌方式设置的样式值,即style属性里面设置的值。
大家都知道,用document.getElementById(‘element’).style.xxx可以获取元素的样式信息,可是它获取的只是DOM元素style属性里的样式规则,对于通过class属性引用的外部样式表,就拿不到我们要的信息了。 DOM标准里...
CSS的样式分为三类: 内嵌样式:是写在Tag里面的,内嵌样式只对所有的Tag有效。 ... 外部样式表:如果很多网页需要用到同样的样式(Styles),将样式(Styles...currentStyle是IE浏览器的一个属性,返回的是CSS样式对象 el
上面用到了parentNode,这里顺便说说它跟offsetParent,parentElement的区别。 先看看parentNode在w3c的说明: The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a ...
function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(elem.currentStyle){ return elem.currentStyle[name]; }else if(document.defaultView&&document.defaultView....
p == "relative" || p == "absolute" || (this._container.style.position = "relative"); this._container.style.overflow = "hidden"; this._slider.style.position = "absolute"; 如果没有设置Change切换参数...
Javascript获取CSS属性值方法:getComputedStyle和currentStyle 1 .对于元素的内联CSS样式(<div xss=removed>hello),可以直接使用element.style.color来直接获取css属性的值; 2. 但是对于外部定义的css样式使用...
<style type="text/css" title="currentStyle" media="screen"> /* Paginator */ .paginator { font: 14.8px normal Arial, Helvetica, sans-serif; color: #666666; margin-top: 10px; margin-bottom: 5px; ...
document href="{testng:absolutePath('style.css')}" format="text"> test="testng:isFilterSelected('CONF') = 'true'"> .testMethodStatusCONF { } .testMethodStatusCONF { display: none; } ...
这个可以直接使用这个方法: 代码如下:function getDefaultStyle(obj,attribute){ // 返回最终样式函数,兼容IE和DOM,设置参数:元素对象、样式特性 return obj.currentStyle?obj.currentStyle[attribute]:...
我们知道获取元素的实际宽高在IE中可以使用currentStyle属性。但如果没有显示的去设置元素的宽高,那么使用该属性将获取不到,获取的值为auto。如下 代码如下: <div>abcd</div> [removed] var div = document....
1.事件冒泡: //取消冒泡 if(e.stopPropagation){ e.stopPropagation();//w3c定义的APIbiaozhun }else{ e.cancelBubble=true;... return element.currentStyle[stylename]; }else{ //其他浏览器