Jquery教程
Jquery动效
Jquery HTML/CSS
Jquery 事件
jquery常用

jQuery innerHeight()

jQuery innerHeight()方法用于返回第一个匹配元素的内部高度。它包括填充,但不包括边框和边距。
在上图中,您可以看到innerHeight()方法包括填充但不包括边框和边距。
语法:
$(selector).innerHeight()

jQuery innerHeight()方法的示例

让我们以一个示例来演示jQuery innerHeight()方法的效果。
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        alert("Inner height of the div is: " + $("div").innerHeight());
    });
});
</script>
</head>
<body>
<div style="height:100px;width:500px;padding:10px;margin:3px;border:1px solid blue;background-color:lightpink;"></div><br>
<button>Click here to get the inner height of the div</button>
</body>
</html>
输出:

jQuery innerHeight()示例2

让我们以一个示例来演示如何更改每个div的内部高度。
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>innerHeight demo</title>
  <style>
div {
  width: 60px;
  padding: 10px;
  height: 100px;
  float: left;
  margin: 5px;
  background: orange;
  cursor: pointer;
}
.mod {
  background: green;
  cursor: default;
}
</style>
<script src="/jquery-1.10.2.js"></script>
</head>
<body>
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>
<script>
var modHeight = 80;
$("div").one( "click", function() {
  $( this ).innerHeight( modHeight ).addClass( "mod");
  modHeight -= 8;
});
</script>
</body>
</html>
输出:
A
B
C
D
E
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4