jQuery outerWidth() 方法
定義和用法
outerWidth() 方法返回第一個匹配元素的外部寬度。
如下圖所示,此方法包含內邊距和邊框。
提示: 要包含外邊距,請使用 outerWidth(true)。
相關方法
- width() - 設定或返回元素的 CSS 寬度
- height() - 設定或返回元素的高度
- innerWidth() - 返回元素的 CSS 寬度(包括內邊距)
- innerHeight() - 返回元素的 CSS 高度(包括內邊距)
- outerHeight() - 返回元素的高度(包括內邊距和邊框)。
語法
$(selector).outerWidth(includeMargin)
引數 | 描述 |
---|---|
includeMargin | 可選。一個布林值,指定是否包含外邊距
|
親手嘗試 - 示例
包含外邊距
指定是否包含外邊距。
使用相關方法顯示尺寸
如何使用 width()、height()、innerHeight()、innerWidth()、outerWidth() 和 outerHeight()。