存在如下文件:
文件:style/css.css
#main_bottom
{
background-color:Fuchsia;
width:1024px;
height:468px;
border:dotted 2px #00f;}文件:js/script.js
function test()
{
//这里怎么alert出层main_bottom的高度??
}文件:test.html
<link type="text/css" href="style/css.css" rel="Stylesheet" />
<script language="javascript" src="js/script.js"></script>
<div id="main_bottom"></div>
<input type="button" value = "test" onclick="test()" />
文件:style/css.css
#main_bottom
{
background-color:Fuchsia;
width:1024px;
height:468px;
border:dotted 2px #00f;}文件:js/script.js
function test()
{
//这里怎么alert出层main_bottom的高度??
}文件:test.html
<link type="text/css" href="style/css.css" rel="Stylesheet" />
<script language="javascript" src="js/script.js"></script>
<div id="main_bottom"></div>
<input type="button" value = "test" onclick="test()" />
{var o =document.getElementById("main_bottom")
alert(parseInt(o.style.height))
o.style.height = "600px"
alert(o.style.height)
//注意style.height是字符串形式,需要用parseInt做转换为数字才能比较,赋值时最好带上单位
//这里怎么alert出层main_bottom的高度??
}
{
//这里怎么alert出层main_bottom的高度??
var mb=document.getElementById("main_bottom");
alert(mb.offsetHeight);
}
alert(document.getElementById('main_bottom').offsetHeight+'px');
document.getElementById('main_bottom').style.height="500px";
document.defaultView.getComputedStyle(文档对象,null).属性 FF
不过在JQUERY 中是可以取得实际的高度的 $(obj).height()