jQuery outerHeight()方法

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>                    

输出:
在点击按钮之前:
jQuery outerHeight()方法
点击按钮后:
jQuery outerHeight()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程