height

英 [ha?t]? ?美 [ha?t]??

n.身高;高度,海拔;高地;絕頂,頂點(diǎn)

jquery height()方法 語(yǔ)法

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

返回高度:返回第一個(gè)匹配元素的高度。如果不為該方法設(shè)置參數(shù),則返回以像素計(jì)的匹配元素的高度。

語(yǔ)法:$(selector).height()

設(shè)置高度:設(shè)置所有匹配元素的高度。

語(yǔ)法:$(selector).height(length)

參數(shù):

參數(shù)描述
length? ??可選。規(guī)定元素的高度。如果沒有規(guī)定長(zhǎng)度單位,則使用默認(rèn)的 px 單位。

使用函數(shù)設(shè)置高度:使用函數(shù)來設(shè)置所有匹配元素的高度。

語(yǔ)法:$(selector).height(function(index,oldheight))

參數(shù):

參數(shù)描述
function(index,oldheight)規(guī)定返回被選元素新高度的函數(shù)。
index?可選。接受選擇器的 index 位置
oldvalue?可選。接受選擇器的當(dāng)前值。

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>
運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例