在jQuery中,获取元素高度的函数有3个,它们分别是height()、 innerHeight()outerHeight()

与此相对应的是,获取元素宽度的函数也有3个,它们分别是width()、 innerWidth()outerWidth()

【补充1】css('width')中的width即是元素内容区的宽度,和width()一样。
      但是width()返回的是个数字,css('width')返回的是带单位的字符串。

    【补充2】若是匹配了一系列元素,那么width()或者css()等方法只返回匹配的第一个元素的值

在这里,我们以height()innerHeight()outerHeight()3个函数为例,来详细介绍它们之间的区别。

下面我们以元素element的盒模型为例来介绍它们之间的区别。

函数 高度范围 jQuery版本 支持写操作
height() height 1.0+ 1.0+
innerHeight() height + padding 1.2.6+ 1.8.0+
outerHeight() height + padding + border 1.2.6+
outerHeight(true) height+padding+border+margin 1.2.6+

1、 只有height()函数可用于windowdocument对象。
2、 "支持写操作"表示该函数可以为元素设置高度值。
3、 1.4.1+ height()新增支持参数为函数(之前只支持数值)。
4、 1.8.0+ innerHeight()支持参数为数值或函数。

现在,我们参考以下HTML + jQuery示例代码:运行代码

<div id="element" style="margin:5px; padding:10px; width:100px; height:100px; border:1px solid #000;"></div>

<script type="text/javascript">var $ele = $("#element");

// height() = height(100) = 100document.writeln( $ele.height() ); // 100

// innerHeight() = height(100) + padding(10*2)= 120 document.writeln( $ele.innerHeight() ); // 120

// outerHeight() = height(100) + padding(10*2) + border(1*2) = 122 document.writeln( $ele.outerHeight() ); // 122

// outerHeight(true) = height(100) + padding(10*2) + border(1*2) + margin(5*2) = 132 document.writeln( $ele.outerHeight(true) ); // 132</script>

jquery 之height(),innerHeight(),outerHeight()方法区别详解的更多相关文章

  1. Jquery中的height(),innerHeight(),outerHeight()的区别

    前言 最近练习做弹窗,遇到height(),innerHeight(),outerHeight()的区别. 根据下面的盒模型来了解三者的区别. height():element的height; inn ...

  2. JQuery动画animate的stop方法使用详解

    JQuery动画animate的stop方法使用详解 animate语法: 复制代码 代码如下: $(selector).animate(styles,speed,easing,callback) 复 ...

  3. Jquery中find与each方法使用详解

    本文实例讲述了jQuery中find与each方法用法.分享给大家供大家参考.具体如下: 一.find()方法 jquery选择器非常强大,利用css的命名规约,可以更快更方便的找出想要的元素. 图解 ...

  4. jQuery中mouseleave和mouseout的区别详解

    很多人在使用jQuery实现鼠标悬停效果时,一般都会用到mouseover和mouseout这对事件.而在实现过程中,可能会出现一些不理想的状况. 先看下使用mouseout的效果: <p> ...

  5. Jquery中attr与prop的区别详解

    prop()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性,返回值是空字符串. attr()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性, ...

  6. jQuery height()、innerHeight()、outerHeight()函数的区别详解

    参考来源:http://www.jb51.net/article/84897.htm 代码示例(可复制到编辑器直接打开): <!DOCTYPE html> <html lang=&q ...

  7. Jquery中的 height(), innerHeight() outerHeight()区别

    jQuery中的 height innerHeight outerHeight区别 标准浏览器下: height:高度 innerHeight:高度+补白 outerHeight:高度+补白+边框,参 ...

  8. ajax方法参数详解与$.each()和jquery里面each方法的区别

    JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...

  9. jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解

    jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解 jQuery中操纵元素属性的方法: attr(): 读或者写匹配元素的属性值. removeAttr(): 从匹配的 ...

随机推荐

  1. 由linux下的多进程编程引发的关于进程间隔离的思考

    源代码放到了三个文件中: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include & ...

  2. SSAS中角色(Role)定义需要注意的两个地方

    开发过SSAS Cube的朋友应该都知道,我们可以在SSAS中设置若干个角色,把windows账号放入这些角色中来限制不同的windows账号可以看到的数据有哪些,这里有两点需要注意一下. 首先在Cu ...

  3. AMD机制与cMD的区别和概念简要介绍

    1.http://www.cnblogs.com/dojo-lzz/p/4707725.html 2.http://blog.chinaunix.net/uid-26672038-id-4112229 ...

  4. android显示当前时间

    SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");        Date c ...

  5. Android的init过程(二):初始化语言(init.rc)解析【转】

    转自:http://www.cnblogs.com/nokiaguy/p/3164799.html Android的init过程(一) 本文使用的软件版本 Android:4.2.2 Linux内核: ...

  6. org.apache.commons.httpclient

    org.apache.commons.httpclient /** * post 方法 * @param url * @param params * @return */ public static ...

  7. 关于hibernate对应关系之后取值的问题

    hibernate对应关系之后取值,比如一对一关系,取不到值,需要检查PO类中是否生成了getter及setter方法.

  8. prop

    用法:prop(属性|key,value|fn) 用例:点击全选/取消全选 // 全选 和全不选 $("#check_all").click(function () { if ($ ...

  9. SQLite详解

    一.新建SQLite操作类(继承SQLiteOpenHelper) public class SQLiteTest extends SQLiteOpenHelper { final static St ...

  10. Android 内存优化 (防Memory Leak)

      在之前的 Android 内存管理 &Memory Leak & OOM 分析 中,说到了Android的内存管理相关的原理,也能了解到Android Memory Leak 和 ...