日期:2014-05-16  浏览次数:20524 次

为什么总获得不到浏览器高度?总是0
var   w=window.document.body.offsertWidth;
宽能获得。
var   h   =   window.document.body.offsertHeight;
h   次次是   0怎么回事》》

代码:
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
<script   language= "javascript ">
function   pp()
{
var   w=window.document.body.offsertWidth;
var   h=window.document.body.offsertHeight;
alert(h);
var   z=10;
var   x=parseInt(document.getElementById( "l1 ").style.left);
var   y=parseInt(document.getElementById( "l1 ").style.top);
document.getElementById( "l1 ").style.left=x+3;
document.getElementById( "l1 ").style.top=y+z;

setTimeout( "pp() ",200);
}
</script>
<style   type= "text/css ">
<!--
body   {
background-color:   #FF9900;
}
#l1   {
position:absolute;
left:51px;
top:19px;
width:320px;
height:201px;
z-index:1;
}
-->
</style> </head>

<body   onload= "pp() ">
<div   id= "l1 "   style= "left:0px;top:0px "> <img   src= "矛.gif "   width= "323 "   height= "242 "   /> </div>
</body>
</html>


------解决方案--------------------
解释参见
http://blog.csdn.net/net_lover/archive/2006/08/25/1116488.aspx
------解决方案--------------------
不同的写法是因果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

规范的不同造成的