.outerWidth()

.outerWidth( [ includeMargin ] ) 官网原E文: Integer

描述: 为匹配的元素集合中获取第一个元素的当前计算宽度值,包括padding,border。

  • version added: 1.2.6.outerWidth( [ includeMargin ] )

    includeMargin一个表明是否在计算时包含元素的margin的布尔值。

返回元素的宽度,一直包括left 和 right padding值,border值和可选择性的margin。单位为像素。

如果 includeMargin省略或者false,padding 和 border会被包含在计算中;如果true,margin也会被包含在计算中 。

这个方法不适用于window and document对象,可以使用.width()代替。

例子:

获取一个段落的outerWidth。

<!DOCTYPE html>
<html>
<head>
  <style>
  p { margin:10px;padding:5px;border:2px solid #666; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p>Hello</p><p></p>
<script>var p = $("p:first");
$("p:last").text( "outerWidth:" + p.outerWidth()+ " , outerWidth(true):" + p.outerWidth(true) );

</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订