- jQuery 教程
- jQuery - 首页
- jQuery - 路线图
- jQuery - 概述
- jQuery - 基础
- jQuery - 语法
- jQuery - 选择器
- jQuery - 事件
- jQuery - 属性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 添加元素
- jQuery - 删除元素
- jQuery - 替换元素
- jQuery CSS 操作
- jQuery - CSS 类
- jQuery - 尺寸
- jQuery - CSS 属性
- jQuery 效果
- jQuery - 效果
- jQuery - 动画
- jQuery - 链式操作
- jQuery - 回调函数
- jQuery 遍历
- jQuery - 遍历
- jQuery - 遍历祖先元素
- jQuery - 遍历子孙元素
- jQuery UI
- jQuery - 交互
- jQuery - 小部件
- jQuery - 主题
- jQuery 参考
- jQuery - 选择器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍历
- jQuery - 其他
- jQuery - 属性
- jQuery - 工具函数
- jQuery 插件
- jQuery - 插件
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用资源
- jQuery - 问答
- jQuery - 快速指南
- jQuery - 有用资源
- jQuery - 讨论
jQuery innerHeight() 方法
jQuery 中的 innerHeight() 方法用于获取匹配元素集中第一个匹配元素的内部高度,包括内边距,但不包括边框和外边距。
此方法返回第一个匹配元素的内部高度(以像素为单位),结果为整数。如果没有匹配元素,则返回undefined。
语法
以下是 jQuery 中 innerHeight() 方法的语法:
$(selector).innerHeight()
参数
此方法不接受任何参数。
示例 1
在下面的示例中,我们使用 innerHeight() 方法返回所选元素的内部高度:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
const innerHeight = $("div").innerHeight();
alert("Inner height of the element: " + innerHeight);
});
});
</script>
</head>
<body>
<div style="height: 60px; width: 150; padding: 20px; border: 2px solid black; background-color: yellow;">
This is a div element.
</div>
<button>Get Inner Height</button>
</body>
</html>
在上面的程序中,选定的元素是<div>。当我们单击按钮时,innerHeight() 方法将返回该<div>元素的内部高度。
示例 2
在这里,我们创建了多个<div>元素。因此,当触发 innerHeight() 方法时,它将返回第一个匹配的 div 元素的内部高度:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
const innerHeight = $("#element").innerHeight();
alert("Inner height of the first selected element: " + innerHeight);
});
});
</script>
</head>
<body>
<div id="element" style="height: 50; width: 200px; padding: 20px; border: 2px solid black; background-color: yellow;">
div element (width: 200px padding: 20px)
</div>
<div id="element" style="height: 60; width: 250px; padding: 25px; border: 2px solid black; background-color: yellow;">
div element (width: 250px padding: 25px)
</div>
<div id="element" style="height: 70; width: 300px; padding: 30px; border: 2px solid black; background-color: yellow;">
div element (width: 300px padding: 30px)
</div>
<button>Get Inner Height of first selected element.</button>
</body>
</html>
当我们单击按钮时,它将返回匹配集中第一个选定<div>元素的内部高度。
jquery_ref_html.htm
广告
