jQuery | height()和innerHeight()及其示例

这个 高度() 是jQuery中的一个内置方法,用于检查元素的高度,但不会检查元素的填充、边框和边距。 语法:

null
$("param").height()

参数: 此函数不接受任何参数。 返回值: 它返回所选元素的高度。

显示height()函数工作的jQuery代码
代码#1:

< html >
< head >
jquery/3.3.1/jquery.min.js"></ script >
< script >
$(document).ready(function() {
$("button").click(function() {
var msg = "";
msg += "height of div: " + $("#demo").height();
$("#demo").html(msg);
});
});
</ script >
< style >
#demo {
height: 150px;
width: 350px;
padding: 10px;
margin: 3px;
border: 1px solid blue;
background-color: lightgreen;
}
</ style >
</ head >
< body >
< div id = "demo" ></ div >
< button >Click Me!!!</ button >
< p >Click on the button and check the height of the
element(excluding padding).</ p >
</ body >
</ html >


输出: 在点击“点击我”按钮之前- 图片[1]-jQuery | height()和innerHeight()及其示例-yiteyi-C++库 点击“点击我”按钮后- 图片[2]-jQuery | height()和innerHeight()及其示例-yiteyi-C++库

jQuery 还包括 内部高度() 方法,即用于检查包括衬垫在内的元件的内部高度。 语法:

$("param").innerHeight()

参数: 此函数不接受任何参数。 返回值: 它返回所选元素的内部高度。 代码#2:

< html >
< head >
jquery/3.3.1/jquery.min.js"></ script >
< script >
$(document).ready(function() {
$("button").click(function() {
var msg = "";
msg += "Inner Height of div: " + $("#demo").
innerHeight() + "</ br >";
$("#demo").html(msg);
});
});
</ script >
</ head >
< style >
#demo {
height: 150px;
width: 350px;
padding: 10px;
margin: 3px;
border: 1px solid blue;
background-color: lightgreen;
}
</ style >
< body >
< div id = "demo" ></ div >
< button >Click Me!!!</ button >
< p >Click on the button and check the innerHeight of
an element(includes padding).</ p >
</ body >
</ html >


输出: 在点击“点击我”按钮之前- 图片[3]-jQuery | height()和innerHeight()及其示例-yiteyi-C++库 点击“点击我”按钮后- 图片[4]-jQuery | height()和innerHeight()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享