本文概述
- jQuery innerHeight()方法的示例
- jQuery innerHeight()示例2
在上图中, 你可以看到innerHeight()方法包括填充, 但不包括边框和边距。
句法:
$(selector).innerHeight()
jQuery innerHeight()方法的示例让我们以一个示例来演示jQuery innerHeight()方法的效果。
<
!DOCTYPE html>
<
html>
<
head>
<
script src="https://ajax.googleapis.com/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="http://img.readke.com/220429/211T92W0-1.jpg">
<
/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>
【jQuery innerHeight()】立即测试
推荐阅读
- jQuery externalHeight()
- jQuery offset()
- jQuery mouseup()
- jQuery mouseover()
- jQuery mouseout()
- jQuery mouseleave()
- jQuery mouseenter()
- jQuery mousedown()
- jQuery load()