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 获取样式的更多相关文章

  1. style.attr,currentStyle,getComputedStyle获取元素css

    老朋友object.style.attr 平常我们都是使用object.style.attr的方式来获取元素的属性, 但是这种方法具有很大的局限性——只能获取内联样式, 而下面的两种方法可以获取到元素 ...

  2. currentStyle&getComputedStyle获取属性

    方法如下: function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; // IE 中的方法 } ...

  3. JS之获取样式

    基本代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  4. getComputedStyle与currentStyle获取样式(style/class)

    今天看jQuery源码CSS部分,里面用到了currentStyle和getComputedStyle来获取外部样式. 因为elem.style.width只能获取elem的style属性里的样式,无 ...

  5. getComputedStyle与currentStyle获取样式

    转载自:https://segmentfault.com/a/1190000007477785 CSS的样式分为三类: 内嵌样式:是写在标签里面的,内嵌样式只对所在的标签有效内部样式:是写在HTML里 ...

  6. style设置/获取样式的问题 和 offsetWidth/offsetHeight的问题

    style设置/获取样式的问题:1.js通过style方法    --加样式:加的是行间样式 oDiv.style.width="20"+'px';    --取样式:取得是行间样 ...

  7. 原生js获取样式

    js中的获取样式是在是让人头疼,为了方便兼容多个浏览器,把设置样式封装成一个函数. 函数如下: function getStyle(element, property) { var value = e ...

  8. 利用原生JavaScript获取样式的方式小结

    来源:http://www.ido321.com/930.html ps:是获取样式,不是设置样式.若没有给元素设置样式值,则返回浏览器给予的默认值.(论坛整理) 1.element.style:只能 ...

  9. style currentStyle getComputedStyle的区别和用法

    先介绍下层叠样式表的三种形式: 1.内联样式,在html标签中style属性设置. <p style="color:#f90">内联样式</p> 2.嵌入样 ...

随机推荐

  1. ibatis 参数之 String

    <select id="query_cust_name" resultClass="_custForm" parameterClass="Str ...

  2. win7 64 VC++ ado方式连接access 连接字符串

    运行环境:win7 64       vc++6.0       office 2007  32位(access 2007) 我用的是ado方式连接access数据库,(现在的Win7系统中安装的一般 ...

  3. Service Worker 缓存文件处理

    交代背景 前段时间升级了一波Google Chrome,发现我的JulyNovel站点Ctrl+F5也刷新不了,后来发现是新的Chrome已经支持Service Worker,而我的JulyNovel ...

  4. 在.net Core中使用StackExchange.Redis 2.0

    StackExchange.Redis 2.0做了大量的改进包括使用了高性能的IO库System.IO.Pipelines来提升性能以及解决Timeouts问题, 但是在.net Core2.2之前为 ...

  5. Notes on view-dependent Catmull-Clark subdivision surfaces

    - Since we perform elimination after every step of subdivision, the only hanging nodes that we encou ...

  6. ansible 常用模块的使用

    安装 yum -y install ansible 配置文件/etc/ansible/hosts 模块介绍与使用 ping模块 [root@node1 config]# ansible k8s -m ...

  7. 浅谈Android选项卡(一)

    选项卡,这样UI设计在很多方面都存在,window,web,ios,Android. 选项卡的主要作用,不用多介绍,可以在有线的空间内,显示出更多内容,同时也是操作起来也很方便.

  8. iOS开发中UILocalNotification本地通知实现简单的提醒功能

    这段时间项目要求做一个类似的闹钟提醒功能,对通知不太熟悉的我,决定先用到xcode自带的本地通知试试,最终成功的实现了功能,特整理分享下. 它的表现特点: app关闭的时候也能接收和显示通知. app ...

  9. ajax跨域请求问题

    ajax是不允许跨域请求的,今天在使用bootstap-table的时候,data-url使用的地址是绝对地址,而非相对地址,因此在载入数据的时候就出错了. 启动的时候使用是 http://127.0 ...

  10. Oracle PL/SQL学习之Hello World(0)

    1.PL/SQL是Oracle数据库的一大创举,让一些复杂繁琐的常规主流编程代码做的编码处理过程,只需要在PL/SQL中使用简短的几句代码就可以解决,并且准确高效.那么遵循惯例,我们学习PL/SQL编 ...