完畢了原來須要用一段來操作做的工作。
這種方法不適用於window
和 document
對象,能夠使用.width()
取代。
以下是其簡介
outerWidth(options)
獲取第一個匹配元素外部寬度(默認包含補白和邊框)。
此方法對可見和隱藏元素均有效。
返回值:Integer 一個整數值 不帶"px"
參數:
options(Boolean) : 默認值為false 設置為 true 時,計算邊距在內。
演示樣例:
獲取第一段落外部寬度。
HTML 代碼:
<div>
<div id="test" style="width:80px;margin:10px;"></div>
</div>
jQuery 代碼:
var w = $("#test").outerWidth(true);
$("#test").html(w);
結果:
<div>
<div id="test" style="width:80px;margin:10px;">100</div>
</div>
outerHeight(options)
獲取第一個匹配元素外部高度(默認包含補白和邊框)。
此方法對可見和隱藏元素均有效。
返回值:Integer
參數:
options(Boolean) : 默認值為false 設置為 true 時,計算邊距在內。
演示樣例:
獲取第一段落外部高度。
HTML 代碼:
<div>
<div id="test" style="height:20px;margin:10px;"></div>
</div>
jQuery 代碼:
var h = $("#test").outerHeight(true);
$("#test").html(h);
結果:
<div>
<div id="test" style="height:20px;margin:10px;">40</div>
</div>
</div>