jQuery outerHeight()方法
jQuery的outerHeight()方法是用来寻找指定元素的外部高度。一个元素的外部高度包括padding和border。
语法:
$(selector).outerHeight(includeMargin)
参数:该方法接受单个参数includeMargin,这是可选的。它包含一个布尔值,用于指定是否包含保证金。如果includeMargin被设置为 “true”,那么保证金就被包括在内,否则就不包括。默认情况下,includeMargin设置为false。
下面的例子说明了jQuery中的outerWidth()方法。
例子:这个例子显示一个元素的外部高度。
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- Script to return outer height -->
<script>
(document).ready(function() {
("button").click(function() {
alert("Outer height of div: "
+ $("div").outerHeight());
});
});
</script>
<!-- Style to create box using padding
and margin -->
<style>
.geeks {
height: 80px;
width: 200px;
padding: 5px;
margin: 5px;
border: 2px solid black;
background-color: green;
text-align: center;
}
</style>
</head>
<body>
<div class="geeks">
GeeksforGeeks
</div>
<button>Click Here to display outer height</button>
</body>
</html>
输出:
在点击按钮之前:
点击按钮后: