<script language="javascript" type="text/javascript">
var he=document.body.clientHeight-105
document.write("<div id=tt style=height:"+he+";overflow:hidden>")
</script>
请问这段代码哪里有错误

解决方案 »

  1.   

    document.write("<div id=tt style=height:"+he+";overflow:hidden>")
    ==============
    document.write("<div id='tt' style='height:"+he+"' overflow:hidden>")alert(document.body.clientHeight) 是否为0
      

  2.   


    此时body没有加载,所以document.body is null
    所以如果想获取body的高度可以写在onload方法里
    window.onload = function() {
    var he=document.body.clientHeight-105
    };
      

  3.   

    这里改后明显错误, overflow应为style; 而且, height要加px否则无效
    "<div id='tt' style='height:" + he + "px;overflow:hidden;'></div>"2L说的也对, 要获取body必须onload后执行, 否则DOM中不存在body