js无法更改div的高度,也获取不到

很简单一个demo练习,想实现移入到bottom上时top的高度会变大。但试了好多次不知道为什么出错。报错的内容也看不懂什么意思。请大神帮我看一下。
<!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">为什么移入你没反应</div>
</div>

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

top.style.height='600px';// 无法设置高度



/*var abc=getStyle(top,'height');
console.log(abc);
//另外,这里试着获取top的当前显示的高度也不行
*/

}

function getStyle(obj,attr)

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

</script>
</html>

阅读 2.9k
1 个回答

top
是window的属性
换句话说话 你别去用,因为你用不了。。
你换个 top1 就行了
图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题