在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. [python] No module named _sysconfigdata_nd

    when setting python environment in Ubuntu13.04, i got this error: ImportError: No module named _sysc ...

  2. 基于时间点恢复数据库stopat

    create database newtestdb use newtestdbgo drop table t1go create table t1 (id int not null identity( ...

  3. PIC18F中断定时器

    //基于MCC18编译器,使用HI-PICC不可用 //-------------------------------------------- #include <p18F452.h> ...

  4. JetBrains WebStorm 8 注册码

    UserName:William===== LICENSE BEGIN =====45550-1204201000001SzFN0n1bPII7FnAxnt0DDOPJAINauvJkeVJBuE5b ...

  5. 批处理命令——echo 和 @

    [1]echo 命令简介 echo 命令的常见用法(必须掌握)分为以下几种情况: 一.无参数 作用:显示当前echo的状态:处于打开或关闭状态. 新建一个文本文件,命名为echo,修改类型为bat,用 ...

  6. 电脑远程工具:mstsc

    外网远程控制:电脑远程连接在开始程序中搜:mstsc  然后直接敲IP地址 工具:dell sonicwall netextender.exe    mstsc.exe 内网远程控制:使用TeamVi ...

  7. POI读取/写入Excel文件

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  8. PHP gmdate() 函数

    定义和用法 gmdate() 函数格式化 GMT/UTC 日期/时间. 同 date() 函数 类似,不同的是返回的时间是格林威治标准时(GMT). 语法 gmdate(format,timestam ...

  9. 实现Ecshop商品跳到淘宝、京东等的购买链接

    今天简单的实现了一下ecshop商品导出到第三方的购买链接功能.大致思路是给商品添加一个buy_link的text字段,存为json结构,然后通过json解析输出到商品购买页面 1.添加字段 增加购买 ...

  10. C语言中使用静态函数的好处

    C语言中使用静态函数的好处: 静态函数会被自动分配在一个一直使用的存储区,直到退出应用程序实例,避免了调用函数时压栈出栈,速度快很多. ???(对这个不是很理解)其实我觉得上面这种说法是错误的,它的主 ...