style和getComputedStyle(ff)和currentStyle
obj.style:这个方法只能JS只能获取写在html标签中的写在style属性中的值(style=”…”),而无法获取定义在<style type="text/css">里面的属性。
IE中使用的是obj.currentStyle方法,而FF是用的是getComputedStyle 方法
<style type=”text/css”>
<!–
.ss{color:#cdcdcd;}
–>
</style>
</head>
<body>
<div id=”css88″ class=”ss” style=”width:200px; height:200px; background:#333333″>JS获取CSS属性值</div>
<script type=”text/javascript”>
alert(document.getElementById(“css88″).style.width);//200px
alert(document.getElementById(“css88″).style.color);//空白
</script>
</body>
#myDiv {
background-color:blue;
width:100px;
height:200px;
}
</style>
<body>
<div id ="myDiv" style=" border:1px solid black"></div>
<script>
var myDiv = document.getElementById("myDiv");
var computedStyle = document.defaultView.getComputedStyle(myDiv, null);
alert(computedStyle.backgroundColor); //"red"
alert(computedStyle.width); //"100px"
alert(computedStyle.height); //"200px"
alert(computedStyle.border); //在某些浏览器中是“1px solid black”
</script
<span style="font-family:Arial;font-size:14px;">var myDiv = document.getElementById("myDiv");
var computedStyle = myDiv.currentStyle;
alert(computedStyle.backgroundColor); //"red"
alert(computedStyle.width); //"100px"
alert(computedStyle.height); //"200px"
alert(computedStyle.border); //undefined</span>
style和getComputedStyle(ff)和currentStyle的更多相关文章
- 获取css样式,style、getComputedStyle及currentStyle的区别
样式表有三种: 内嵌样式:<div id="box" style="color:red">box</div>,style写在html中的 ...
- getComputedStyle/currentStyle/style之间的爱恨情仇
getComputedStyle是? getComputedStyle是一个可以获取当前元素所有最终使用的CSS属性值.返回的是一个CSS样式声明对象([object CSSStyleDeclarat ...
- Js获取元素样式值(getComputedStyle¤tStyle)兼容性解决方案
因为:style(document.getElementById(id).style.XXX)只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的. 一般js获取内部样式和外部样式使用 ...
- CSSOM之getComputedStyle,currentStyle,getPropertyValue,getAttribute
js关于CSSOM编程的样式相关几个常用的方法 webkit:getComputedStyle,getPropertyValue IE:currentStyle,getAttribute 前言 jqu ...
- 函数语法:currentStyle、getComputedStyle兼容判断
var oDiv = document.getElementById('aa'); if(oDiv.currentStyle){ var style = oDiv.currentStyle; aler ...
- getComputedStyle 方法
一:getComputedStyle getComputedStyle是一个可以获取当前元素所有最终使用的CSS属性值.返回的是一个CSS样式声明对象([object CSSStyleDeclarat ...
- 获取元素CSS值之getComputedStyle方法熟悉
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=2378 一.碎碎念~前 ...
- getComputedStyle方法获取元素CSS值
javascript的style属性只能获取内联样式,对于外部样式和嵌入式样式需要用currentStyle属性.但是,currentStyle在FIrefox和Chrome下不支持,需要用getCo ...
- 7处ff与ie中读写html、css相关属性的不同之处
1. float样式属性 IE syntax: document.getElementById("test").style.styleFloat = "left" ...
随机推荐
- debian文本配置网络备忘:/etc/network/interfaces
我装了wheezy有gnome3,xfce4: 郁闷的是,不论在gnome还是xfce4中 我都无法图形登录或者切换用户到root: 而且我无法在普通用户下图形修改网络配置: 我也搜索不到启用root ...
- OpenCV——基本图形绘制(椭圆、圆、多边形、直线、矩形)
//绘制椭圆 void DrawEllipse(Mat img, double angle) { ; ; ellipse(img, Point(WINDOW_WIDTH / , WINDOW_WIDT ...
- C++使用默认参数的构造函数
我们可以想象一个这样的场景:某一天书店整理库存,发现了一些非常老的书,为了尽快清空库存,店主想了一下,决定开展一个大甩卖活动,所有的这些书全部以五美元的价格出售.此时如果需要尽快将这些书的信息录入到书 ...
- python3 Beautifulsoup <class 'bs4.element.ResultSet'> <class 'bs4.element.Tag'> 取值
1.<class 'bs4.element.ResultSet'> 这里是字典外套了一个列表 textPid = pid[0] 2.<class 'bs4.element.Tag ...
- defaultdict - update - pymysql
defaultdict 的例子 使用list作为default_factory,他很容易的将一个以键值形式表现的序列分组成一个字典列表 >>> s = [('yellow', 1), ...
- TensorFlow入门
Win10下pycharm安装tensorflow: 1.安装git,这样就会有windows powerShell 2.安装python3.x,配置环境变量 3.安装pip,下载地址是:https: ...
- Linux下MySQL安装与操作
sudo apt-get update //用于更新源,获取软件包列表 sudo apt-get upgrade //用于升级指定软件包 install //安装 remove //移除软件包 aut ...
- python下安装lxml
首先在环境变量path中添加:C:\Python27\Scripts 然后打开cmd命令窗口,输入以下命令: easy_install virtualenv easy_install lxml 这样 ...
- Eclipse-快捷键大全(转载)
快速展开类:ctrl + shift +*(小键盘) 快速关闭类:ctrl+ shift + /(小键盘) Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl ...
- 番外篇:因为一个固态导致的——系统重装与JAVA软件环境下载安装配置
第一步:拆机改装 最近想换个固态硬盘提提速度,就买了个,然后拧下后盖螺丝,将键盘盖拿下,中间有两个根线连着把扣打开就可以了,将新的固态硬盘装到原本的机械硬盘的地方,又买了个光驱托盘改装位将光驱位装上了 ...