getComputedStyle获取css属性与IE下的currentStyle获取到的值不同
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style>
.button {
height: 2em;
line-height:24px;
//border: 0;
//border-radius: .2em;
background-color: #34538b;
color: #fff;
font-size: 12px;
font-weight: bold;
}
</style>
</head>
<body>
<input type="button" id="button" class="button" value="点击我,显示高度" />
<script>
document.getElementById("button").onclick = function() {
//var oStyle = this.currentStyle? this.currentStyle : window.getComputedStyle(this, null);
var oStyle = this.currentStyle || window.getComputedStyle(this, null);//IE下获取是2em,Firefox下获取的是24px;浏览器默认1em=16px;
alert(oStyle.height);
};
</script>
</body>
</html>
getComputedStyle获取css属性与IE下的currentStyle获取到的值不同的更多相关文章
- js中获取css属性
直接获取 window.onload = function() { var but = document.getElementById('button'); var div = document.ge ...
- JS中使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值
在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式,方法有很多很多,现在仅把我经常用的方法总结如: 1. obj.style:这个方法只能JS只能获取写在html标签中的写在style属性 ...
- 自定义属性,innerHTML,outerHTML,dom节点的获取,className,tagName,更改或者是获取css属性
01.自定义属性 1.自定义属性: 作用:保存数据 通用的自定义属性的前缀 data-属性="属性值" 注:自定义的属性不能通过 元素.属性 取属性值 ,需使用getAttribu ...
- JavaScript如何获取css属性
原文:JavaScript如何获取css属性 在web开发中,很多时候我们需要用JavaScript对网页的样式进行修改,接下来,我们就来看一下我们该如何访问css属性,针对不同情况及案例来进行分析. ...
- js原生获取css属性
原文参考http://blog.csdn.net/lzding/article/details/46317777 1.写在dom上的属性,内联样式 <div id="box" ...
- JS使用getComputedStyle()方法获取CSS属性值
在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式,方法有很多很多,现在仅把我经常用的方法总结如下: 1. obj.style:这个方法只能JS只能获取写在html标签中的写在style属 ...
- JS 获取CSS属性值
obj: 元素对象 attribute: 属性 返回值:该对象这个属性的值 function getDefaultStyle(obj,attribute){ // 返回最终样式函数,兼容IE和DOM, ...
- js获取css属性方法
function getDefaultStyle(obj,attribute){ return obj.currentStyle?obj.currentStyle[attribute] : docum ...
- 原生js使用getComputedStyle方法获取CSS内部属性值
在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式, 1.下面的方法只能JS只能获取写在html标签中的写在style属性中的值(style=”…”),而无法获取定义在<style ...
随机推荐
- java基础讲解07-----数组
1.什么是数组 2.怎么使用数组 package test; public class ShuZu { public static void main(String[] args ...
- Windows 7/8/8.1 误删EFI启动项,无法开机解决方式(U盘+原版镜像)
今天手贱把Windows 7的启动项删了.由于是GPT分区,EFI引导的,又不像MBR那般easy解决 想想重装系统也麻烦,并且仅仅是删了个启动项而已.就不是必需去费那个时间 想了一下,Windows ...
- php处理XML数据
把XML转换成对象直接调用里面的属性 <?php$note=<<<XML<note><to>Tove</to><from>Jan ...
- 【Android应用开发技术:用户界面】布局管理器
作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...
- MVC & Entity Framework(1)- 开发环境
一直都有接触asp.net mvc,希望自己借此次机会把Blog搭起来的同时能够更深入地学习相关知识. ①新建 打开VS2012,新建ASP.Net MVC 4项目,接着选择“空”模板(因为不想用自带 ...
- pow函数
pow函数如果直接强制类型转换成int,会导致精度的损失.如果是int的幂计算,建议重写函数.或者用double型进行计算.
- hdu1025 最大上升字串
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- mybatis的foreach写用法
一.mybatis查询 public abstract List<Model> findByIds(@Param("ids")List<Integer> i ...
- 页面表单里的图片上传ENCTYPE="multipart/form-data"
ENCTYPE="multipart/form-data"用于表单里有图片上传. <form action="<%=basePath %>asyUplo ...
- 配置Docker中国区官方镜像http://get.daocloud.io/ 很好的一个源http://get.daocloud.io/#install-docker
https://www.daocloud.io/mirror#accelerator-doc 配置Docker中国区官方镜像http://get.daocloud.io/ 很好的一个源http://g ...