<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="jquery.js">
</script>
<script>
$(document).ready(function() {
$("button").click(function() {
var txt = "";
txt += "Width of div: " + $("#div1").width() + "</br>";
txt += "Height of div: " + $("#div1").height() + "</br>";
txt += "Inner width of div: " + $("#div1").innerWidth() + "</br>";
txt += "Inner height of div: " + $("#div1").innerHeight() + "</br>";
txt += "Outer width of div: " + $("#div1").outerWidth() + "</br>";
txt += "Outer height of div: " + $("#div1").outerHeight() + "</br>";
txt += "Outer width of div (margin included): " + $("#div1").outerWidth(true) + "</br>";
txt += "Outer height of div (margin included): " + $("#div1").outerHeight(true) + "</br>";
txt += "Document width/height: " + $(document).width();
txt += "x" + $(document).height() + "</br>";
txt += "Window width/height: " + $(window).width();
txt += "x" + $(window).height();
$("#div1").html(txt);
});
});
</script>
</head>
<body>
<div id="div1" style="height:200px;width:500px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
<br>
<button>显示 div 的尺寸</button><a>height:200px--width:500px--padding--10px--margin:3px--border:1px</a>
<p>width() - 返回元素的宽度。</p>
<p>height() - 返回元素的高度。</p>
<p>innerWidth() - 返回元素的宽度(包括内边距)。</p>
<p>innerHeight() - 返回元素的高度(包括内边距)。</p>
<p>outerWidth() - 返回元素的宽度(包括内边距和边框)。</p>
<p>outerHeight() - 返回元素的高度(包括内边距和边框)。</p>
<p>outerWidth(true) - 返回元素的宽度(包括内边距、边框和外边距)。</p>
<p>outerHeight(true) - 返回元素的高度(包括内边距、边框和外边距)。</p>
</body>
</html>
