当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery中outerHeight()方法用法实例教程

jQuery中outerHeight()方法用法实例教程

2019年03月30日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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="https://www.cnblogs.com/" />
<title>outerheight()函数-博客园</title>
<style type="text/css">
p{
  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(){
    $("p").text($("p").outerheight(true))
  })
})
</script>
</head>
<body>
  <p>此处显outerheight数值</p>
  <button>点击查看p的outerheight</button>
</body>
</html>

 

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网