存在如下文件:
文件: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()" />

解决方案 »

  1.   

    写一个函数用什么样的语句重新设置层的高度?直接访问层的style返回空。。
      

  2.   

    function 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的高度?? 

      

  3.   

    document.getElementById("main_bottom").style.height
      

  4.   

    function test()
    {
    //这里怎么alert出层main_bottom的高度??
    var mb=document.getElementById("main_bottom");
    alert(mb.offsetHeight);
      

  5.   

    IE中用currentStyle.height可以返回正确值,但FF中不支持
      

  6.   

    用 offsetHeight 或给<style 一个ID,然后用JS+正则找到相应的height属性+值
    alert(document.getElementById('main_bottom').offsetHeight+'px');
      

  7.   

    设置高度好说直接可以
    document.getElementById('main_bottom').style.height="500px";
      

  8.   

    文档对象.currentStyle.属性     IE
    document.defaultView.getComputedStyle(文档对象,null).属性       FF    
      

  9.   

    对于css定义的obj.style.height必须是内联时才能获取到
      

  10.   

    最终样式是个综合的结果 ,readonly 
    不过在JQUERY 中是可以取得实际的高度的 $(obj).height()