element.offsetWidth:

返回元素的宽度,包括边框和内边距。

element.offsetHeight:

返回元素的高度,包括边框和内边距。

currentStyle:

获取计算后的样式,也叫当前样式、最终样式。优点:可以获取元素的最终样式,包括浏览器的默认值,而不像style只能获取行间样式,所以更常用到。注意:不能获取复合样式如background属性值,只能获取单一样式如background-color等。currentStyle 在ie、opera上是可行的,无法适用于所有浏览器的。

getComputedStyle(
obj , false ):

是支持 w3c (FF12、chrome
14、safari):
在FF新版本中只需要第一个参数,即操作对象,第二个参数写“false”也是大家通用的写法,目的是为了兼容老版本的火狐浏览器。

所以可以这样来写兼容:

 var obj= document.getElmentById("id");
var getStyle = function (obj,attr) {
if(obj.currentStyle){
//
return parseInt(obj.currentStyle[attr]);
}else{
return parseInt(getComputedStyle(obj,false)[attr]);
}
}

currentStyle、getComputedStyle的更多相关文章

  1. style、currentStyle、getComputedStyle区别介绍

    style.currentStyle.getComputedStyle区别介绍 来自:蓝色天空 样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有 ...

  2. style、currentStyle、getComputedStyle(不同浏览器获取css样式)区别介绍

    style.currentStyle.getComputedStyle区别介绍   样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效. 内部样 ...

  3. JavaScript获取HTML元素样式的方法(style、currentStyle、getComputedStyle)

    一.style.currentStyle.getComputedStyle的区别 style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的. currentStyle可以弥补st ...

  4. currentStyle、getComputedStyle 获取样式

    style.height 获取的是行间的样式 currentStyle.height.getComputedStyle(elem,null).height 获取的是 div 的 content 的宽高 ...

  5. javascript 读取内联之外的样式(style、currentStyle、getComputedStyle区别介绍) (转载)

    样式表有三种方式: 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效.   (也称作“内联样式”) 内部样式(internal Style Sheet):是写在 ...

  6. js便签笔记(7)——style、currentStyle、getComputedStyle区别介绍【转载】

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

  7. 函数语法:currentStyle、getComputedStyle兼容判断

    var oDiv = document.getElementById('aa'); if(oDiv.currentStyle){ var style = oDiv.currentStyle; aler ...

  8. js获取样式、currentStyle和getComputedStyle的兼容写法

    currentStyle获取计算后的样式,也叫当前样式.最终样式.优点:可以获取元素的最终样式,包括浏览器的默认值,而不像style只能获取行间样式,所以更常用到.注意:不能获取复合样式如backgr ...

  9. currentStyle与getComputedStyle应用

    getComputedStyle获取的是计算机(浏览器)计算后的样式,但是不兼容IE6.7.8(主要用于非IE浏览器) currentStyle方法兼容IE6.7.8,但是不兼容标准浏览器(主要用于I ...

随机推荐

  1. if分支的四种形式

    分支:——四种if一.if(条件表达式){} 二.if(条件表达式){}else{} 三.if(条件表达式){}else if(条件表达式){}else if(条件表达式){}....else{} 四 ...

  2. visual studio 2015 修改类class 文件模板

    第一步:找到模板文件 路径:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\C ...

  3. win7系统64位plsql的设置

    1. Instant Client Downloads for Microsoft Windows (32-bit) 我下载的是: instantclient-basic-win32-11.2.0.1 ...

  4. mysql导出数据到excel表中

     mysql>  select b.username,a.subject,a.money,FROM_UNIXTIME(a.ctime) from shop_pay a   INNER JOIN ...

  5. mysql 时间戳按指定格式(Y-m-d)取出

    之前做采集脚本,把采集的时间按unix时间戳的形式取出    那么在写sql语句的时候,需要按时间查询相应的记录,页面传进来的$time 是'2014-01'之类的字符串,那么怎么写sql呢 $sql ...

  6. 一个纯CSS DIV天气动画图标【转扒的】

    <p> </p> <style><!-- /* SUNNY */ .sunny { -webkit-animation: sunny 15s linear i ...

  7. AspectJ截获操作

    package com.example.aspectjandroidtest; import java.io.BufferedOutputStream; import java.io.ByteArra ...

  8. ACboy needs your help again!--hdu1702

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. Entity Framewor中的 Migration

    http://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx = Code bas ...

  10. JS 禁止浏览器右键菜单和刷新

    <script language="javascript"> //禁止按键F5 document.onkeydown = function(e){ e = window ...