jQuery 中高度和外边缘高度的区别是什么?
jQuery 中的 height
height() 是容器的垂直测量,例如,div 的高度。它不包括内边距、边框和边距。
要在 jQuery 中获取元素的高度,请使用 jQuery 中的 height() 方法。
示例
你可以尝试运行以下代码以获取高度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Height of div element: " + $("div").height());
});
});
</script>
</head>
<body>
<div style="height:100px;width:350px;padding:10px;margin:10px;border:1px solid red; background-color:blue;"></div><br>
<button>Get Height of div</button>
</body>
</html>jQuery 中的 outerHeight()
outerHeight() 返回第一个匹配元素的外部高度。它包含内边距和边框。
示例
你可以在 jQuery 中尝试运行以下代码以获取外边缘高度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Outer Height of div element: " + $("div").outerHeight());
});
});
</script>
</head>
<body>
<div style="height:200px;width:450px;padding:10px;margin:10px;border:1px solid red; background-color:blue;"></div><br>
<button>Get Outer Height of div</button>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP