在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Linux  HTML/ js無法更改div的高度,也獲取不到

js無法更改div的高度,也獲取不到

很簡單一個demo練習(xí),想實(shí)現(xiàn)移入到bottom上時top的高度會變大。但試了好多次不知道為什么出錯。報錯的內(nèi)容也看不懂什么意思。請大神幫我看一下。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
*{margin: 0;padding: 0;}
body{background-color: #fff;font-size: 13px;color: #333;font-family: "微軟雅黑";}
.main{

margin:0 auto;
width: 600px;
/*height: 300px;*/

}
.main .top{

background-color: #ccc;
text-align: center;
font-size: 24px;
height: 50px;
overflow: hidden;

}
.main .bottom{

height: 40px;
line-height: 40px;
background-color: #555;
text-align: center;
color:#fff;

}
</style>
</head>
<body>

<div class="main">
    <div class="top" id="top">就是這個狗日的top不顯示</div>
    <div class="bottom" id="bottom">為什么移入你沒反應(yīng)</div>
</div>

</body>
<script>
var top=document.getElementById('top');
var bottom=document.getElementById('bottom');
bottom.onmouseover=function(){

top.style.height='600px';// 無法設(shè)置高度



/*var abc=getStyle(top,'height');
console.log(abc);
//另外,這里試著獲取top的當(dāng)前顯示的高度也不行
*/

}

function getStyle(obj,attr)

{
    return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,null )[attr];
}

</script>
</html>

回答
編輯回答
雅痞

top
是window的屬性
換句話說話 你別去用,因?yàn)槟阌貌涣?。?br>你換個 top1 就行了
圖片描述

2018年9月1日 16:05