jquery css设置高度的方法是height方法,该方法能返回或设置匹配元素的高度,其设置高度的语法如“$(selector).height(length)”,参数length规定元素的高度。
本文操作环境:Windows7系统、jquery3.2.1&&css3版,DELL G3电脑
jQuery CSS 操作 - height() 方法
height() 方法返回或设置匹配元素的高度。
返回高度
返回第一个匹配元素的高度。
如果不为该方法设置参数,则返回以像素计的匹配元素的高度。
语法
$(selector).height()
设置高度
设置所有匹配元素的高度。
语法
$(selector).height(length)
参数
length
可选。规定元素的高度。
如果没有规定长度单位,则使用默认的 px 单位。
示例:
<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $(".btn1").click(function(){ $("p").height(50); });});</script></head><body><p style="background-color:yellow">This is a paragraph.</p><button class="btn1">改变高度</button></body></html>
效果截图:
推荐学习:《jquery视频教程》
以上就是jquery css怎么设置高度的知识。速戳>>知识兔学习精品课!