<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
#box01{
width: 100px;
height: 100px;
background-color: red;
padding: 10px;
border: 10px solid yellow;
margin: 10px;
}
</style>
<script type="text/javascript">
window.onload = function(){
var btn01 = document.getElementById('btn01');
var box01 = document.getElementById('box01');
btn01.onclick = function(){
/*
clientWidth:
clientHeight:
-这两个属性可以获取元素的可见宽度和高度
-这些属性都是不带PX,返回都是一个数字,可以直接进行计算
-会获取元素宽度和高度,包括内容区和内边距.
-这些属性都是只读的,不能修改.
*/
alert(box01.clientHeight);
alert(box01.clientWidth);
/*
offsetWidth
offsetHeight
-获取元素的整个宽度和高度,包括内容区 内边距和边框
*/
alert(box01.offsetHeight);
}
}
</script>
</head>
<body>
<button id="btn01">点我一下</button>
<br><br>
<div id="box01"></div>
</body>
</html>
JS基础-其它样式相关的属性
最新推荐文章于 2022-06-28 15:41:40 发布