currentStyle、getComputedStyle 获取样式
style.height 获取的是行间的样式
currentStyle.height、getComputedStyle(elem,null).height 获取的是 div 的 content 的宽高,
clientHeight 获取的是 content+padding,
offsetHeight 获取的是content+padding+border。
<script>
window.onload = function(){
var div1 = document.getElementById('div1');
var prop = '';
if(div1.currentStyle){
// IE浏览器下获取行间或样式表样式
prop = div1.currentStyle.height;
}else if(window.getComputedStyle){
// 标准浏览器下获取计算样式,两种写法都可以
// prop = document.defaultView.getComputedStyle(div1,null).height;
prop = window.getComputedStyle(div1,null).height;
}
console.log(prop);
// height:auto; ==》 IE返回的是auto,标准浏览器返回的是实际值
}
</script>
currentStyle、getComputedStyle 获取样式的更多相关文章
- style.attr,currentStyle,getComputedStyle获取元素css
老朋友object.style.attr 平常我们都是使用object.style.attr的方式来获取元素的属性, 但是这种方法具有很大的局限性——只能获取内联样式, 而下面的两种方法可以获取到元素 ...
- currentStyle&getComputedStyle获取属性
方法如下: function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; // IE 中的方法 } ...
- JS之获取样式
基本代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- getComputedStyle与currentStyle获取样式(style/class)
今天看jQuery源码CSS部分,里面用到了currentStyle和getComputedStyle来获取外部样式. 因为elem.style.width只能获取elem的style属性里的样式,无 ...
- getComputedStyle与currentStyle获取样式
转载自:https://segmentfault.com/a/1190000007477785 CSS的样式分为三类: 内嵌样式:是写在标签里面的,内嵌样式只对所在的标签有效内部样式:是写在HTML里 ...
- style设置/获取样式的问题 和 offsetWidth/offsetHeight的问题
style设置/获取样式的问题:1.js通过style方法 --加样式:加的是行间样式 oDiv.style.width="20"+'px'; --取样式:取得是行间样 ...
- 原生js获取样式
js中的获取样式是在是让人头疼,为了方便兼容多个浏览器,把设置样式封装成一个函数. 函数如下: function getStyle(element, property) { var value = e ...
- 利用原生JavaScript获取样式的方式小结
来源:http://www.ido321.com/930.html ps:是获取样式,不是设置样式.若没有给元素设置样式值,则返回浏览器给予的默认值.(论坛整理) 1.element.style:只能 ...
- style currentStyle getComputedStyle的区别和用法
先介绍下层叠样式表的三种形式: 1.内联样式,在html标签中style属性设置. <p style="color:#f90">内联样式</p> 2.嵌入样 ...
随机推荐
- C#中使用Redis学习二 在.NET4.5中使用redis hash操作
上一篇>> 摘要 上一篇讲述了安装redis客户端和服务器端,也大体地介绍了一下redis.本篇着重讲解.NET4.0 和 .NET4.5中如何使用redis和C# redis操作哈希表. ...
- jquery实现简单抽奖功能
一直纠结要怎么用jquery实现抽奖功能,看别人很多都是用flash制作的,找了很多资料,最终找到一个比较适合需求的,我做了些许调整,以下是代码展示(复制下来可以直接使用). 先上图:
- INDEX--索引相关信息查看
--============================================== --查看可能缺失的索引 SELECT mig.* ,migs.* ,mid.* FROM sys.dm ...
- C#设计模式系列:代理模式(Proxy Pattren)
一.引言 在软件开发过程中,有些对象有时候会由于网络或者其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让 ...
- centos7 安装git
centos7下git的安装和配置 git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 ...
- fhq treap——简单又好写的数据结构
今天上午学了一下fhq treap感觉真的很好用啊qwq 变量名解释: \(size[i]\)表示以该节点为根的子树大小 \(fix[i]\)表示随机权值 \(val[i]\)表示该节点的值 \(ch ...
- python列表重复判断
import random import string n = 0; while n<10: str_source = string.ascii_letters + string.digits ...
- OCP题库升级,iZ0-052新加的考题及答案整理-18
18.You want to Install Oracle 11g database software and create a database on ASM Immediately after t ...
- P1158 导弹拦截
P1158 导弹拦截 思路: 按每个点到第一个系统的距离排序,然后预处理出每个点及其之后的点到第二个系统的距离的最大值,再循环一遍枚举答案. 代码: #include <cstdio> ...
- (C/C++) 亂數應用
因為公司需要寫了一個亂數產生測試條件的小程式,再此紀錄下來 int _tmain(int argc, _TCHAR* argv[]) { fstream file; file.open("t ...