淺談jQuery中height與width
jquery中有三個獲取element高度的方法,分別是:height(),innerHeight(),outerHeght(bool);同樣對應(yīng)的有三個獲取element寬度的方法:width(),innerHeight(),outerHeight(bool),這三個方法分別對應(yīng)怎樣的元素屬性,如下圖所示:
從上面的圖可以了解到:height()方法對應(yīng)頂部style設(shè)置的width屬性;
innerHeight()對應(yīng)width+padding-top+padding-bottom;
outerHeight()對應(yīng)width+padding-top+padding-bottom+border-top+border-bottom;
另外看到下面outerHeight與outerWidth的值不一樣是由于outerWidth(bool)方法參數(shù)被設(shè)置成true,
這時會加上margin-top和margin-bottom;
即:outerWidth = width+padding-top+padding-bottom+border-top+border-bottom+margin-top+margin-bottom;
來個簡單的示例吧
<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">請點擊這里</button> </body> </html>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
jQuery.Callbacks()回調(diào)函數(shù)隊列用法詳解
這篇文章主要介紹了jQuery.Callbacks()回調(diào)函數(shù)隊列用法,結(jié)合實例形式詳細(xì)分析了jQuery.Callbacks()回調(diào)函數(shù)隊列的功能、控制標(biāo)志含義與相關(guān)注意事項,需要的朋友可以參考下2016-06-06jQuery中bind,live,delegate與one方法的用法及區(qū)別解析
本篇文章主要是對jQuery中bind,live,delegate與one方法的用法及區(qū)別進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12jquery獲取特定name所有選中的checkbox,支持IE9標(biāo)準(zhǔn)模式
jquery獲取特定name所有選中的checkbox,支持IE9標(biāo)準(zhǔn)模式,需要的朋友可以參考一下2013-03-03