<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>
<title>每天一个JavaScript实例-获取元素当前高度</title>
<style>
#date{width:90%;height:25%;padding:10px;background:red;}
</style>
<script>
window.onload=function(){
varheight=getHeight();
console.log(height);
}
functiongetHeight(){
varheight=0;
vardiv=document.getElementById("date").getBoundingClientRect();
if(div.height){
height=div.height;
}else{
height=div.bottom-div.top;
}
returnheight;
}
</script>
</head>
<body>
<divstyle="width:1000px;height:800px;">
<divid="date">
</div>
</div>
</body>
</html>