1、width() ( height() )
不传参时返回元素的宽度,传参时改变元素的宽度(参数可以为数字,也可以是带像素单位的字符串)
<style>
div{background-color: rebeccapurple;height: 100px;width: 100px;}
</style>
</head>
<body>
<div>
123456
</div>
</body>
</html>
<script>
$("div").height("400px")
$("div").width(300)
</script>
2、innerHeight() ( innerWidth() )
返回元素的height+padding
<style>
div{background-color: rebeccapurple;height: 100px;width: 100px;padding: 10px;margin: 5px;border: 5px solid forestgreen;}
</style>
</head>
<body>
<div>
123456
</div>
</body>
</html>
<script>
console.log($("div").innerHeight(),$("div").innerWidth())//120 120
</script>
3、outerHeight() ( outerWidth() )
不传参时返回border+Height+padding
向方法传入参数true时,返回border+Height+padding+margin
<style>
div{background-color: rebeccapurple;height: 100px;width: 100px;padding: 10px;margin: 20px;border: 5px solid forestgreen;}
</style>
</head>
<body>
<div>
123456
</div>
</body>
</html>
<script>
console.log($("div").outerHeight(),$("div").outerWidth()) //130 130
console.log($("div").outerHeight(true),$("div").outerWidth(true))//170 170
</script>