jquery height()方法


  翻译结果:

height

英 [haɪt]   美 [haɪt]  

n.身高;高度,海拔;高地;绝顶,顶点

jquery height()方法 语法

作用:height() 方法返回或设置匹配元素的高度。

返回高度:返回第一个匹配元素的高度。如果不为该方法设置参数,则返回以像素计的匹配元素的高度。

语法:$(selector).height()

设置高度:设置所有匹配元素的高度。

语法:$(selector).height(length)

参数:

参数描述
length    可选。规定元素的高度。如果没有规定长度单位,则使用默认的 px 单位。

使用函数设置高度:使用函数来设置所有匹配元素的高度。

语法:$(selector).height(function(index,oldheight))

参数:

参数描述
function(index,oldheight)规定返回被选元素新高度的函数。
index 可选。接受选择器的 index 位置
oldvalue 可选。接受选择器的当前值。

jquery height()方法 示例

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>
运行实例 »

点击 "运行实例" 按钮查看在线实例

热门推荐

目录

首页

视频

问答