jQuery outerWidth() 方法
实例
返回 <div> 元素的外部宽度:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){alert("Outer width of div: " + $("div").outerWidth());});});</script></head><body><div style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div><br><button>显示 div 的外部宽度</button><p>outerWidth() - 返回元素的外部宽度(包括填充和边框)</p></body></html>
定义与用法
outerWidth() 方法返回第一个匹配元素的外部宽度。
如下图所示,此方法包括填充和边框。

提示:要包含边距,请使用 outerWidth(true)。
相关方法:
- height() - 设置或返回元素的高度
- width() - 设置或返回元素的宽度
- innerHeight() - 返回元素的高度(包括填充)
- innerWidth() - 返回元素的宽度(包括填充)
- outerHeight() - 返回元素的高度(包括填充和边框)
语法
$(selector).outerWidth(includeMargin)
| 参数 | 描述 |
|---|---|
| includeMargin | 可选。一个布尔值,指定是否包含 margin 边距
|
更多实例
如何使用 width()、height()、innerHeight()、innerWidth()、outerWidth() 和 outerHeight()