服务器之家:专注于服务器技术及软件下载分享
分类导航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服务器之家 - 编程语言 - JavaScript - jQuery中outerHeight()方法用法实例

jQuery中outerHeight()方法用法实例

2021-07-16 18:00jQuery教程网 JavaScript

这篇文章主要介绍了jQuery中outerHeight()方法用法,实例分析了outerHeight()方法的功能、定义及获取第一个匹配元素外部高度的使用技巧,需要的朋友可以参考下

本文实例讲述了jQuery中outerHeight()方法用法。分享给大家供大家参考。具体分析如下:

此方法获取第一个匹配元素外部高度。
默认情况下外部高度是高度(height)、内补白(padding)和边框(border)之和。
如果参数设置为true的话,外补白(margin)尺寸也会算入外部宽度。
此方法对可见和隐藏元素均有效。

可以与outerWidth()方法结合学习。

语法结构:

复制代码 代码如下:
$(selector).outerHeight(options)

 

参数列表:

参数

描述

options

定义是否把外补白(margin)计算在内:
一.fase,边距不计算在内,默认值。
二.true,边距计算在内。

 

实例代码:

 

复制代码 代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.zzvips.com/" />
<title>outerHeight()函数-服务器之家</title>
<style type="text/css">
div{
  background-color:green;
  height:100px;
  width:200px;
  padding:10px;
  margin:10px;
  border:5px solid red;
}  
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").text($("div").outerHeight(true))
  })
})
</script>
</head>
<body>
  <div>此处显outerHeight数值</div>
  <button>点击查看div的outerHeight</button>
</body>
</html>

 

点击按钮可以显示div元素外部高度。

希望本文所述对大家的jQuery程序设计有所帮助。

延伸 · 阅读

精彩推荐