亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

淺談jQuery中height與width

 更新時(shí)間:2015年07月06日 09:30:40   投稿:hebedich  
本文給大家簡(jiǎn)單談?wù)刯Query中的獲取高度和寬度的height和width方法,這里總結(jié)一下,方便大家更好的理解,有需要的小伙伴可以參考下。

jquery中有三個(gè)獲取element高度的方法,分別是:height(),innerHeight(),outerHeght(bool);同樣對(duì)應(yīng)的有三個(gè)獲取element寬度的方法:width(),innerHeight(),outerHeight(bool),這三個(gè)方法分別對(duì)應(yīng)怎樣的元素屬性,如下圖所示:

從上面的圖可以了解到:height()方法對(duì)應(yīng)頂部style設(shè)置的width屬性;

innerHeight()對(duì)應(yīng)width+padding-top+padding-bottom;

outerHeight()對(duì)應(yīng)width+padding-top+padding-bottom+border-top+border-bottom;

另外看到下面outerHeight與outerWidth的值不一樣是由于outerWidth(bool)方法參數(shù)被設(shè)置成true,
這時(shí)會(huì)加上margin-top和margin-bottom;
即:outerWidth = width+padding-top+padding-bottom+border-top+border-bottom+margin-top+margin-bottom;

來個(gè)簡(jiǎn)單的示例吧

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("button").click(function(){
 $("#id200").width("300px");
 });
});
</script>
</head>
<body>
<div id="id100" style="background:yellow;height:100px;width:100px">HELLO</div>
<div id="id200" style="background:yellow;height:100px;width:100px">W3SCHOOL</div>
<button type="button">請(qǐng)點(diǎn)擊這里</button>
</body>
</html>

以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論