日期:2014-05-17  浏览次数:20503 次

document.documentElement.clientWidth和document.body.clientWidth的区别在哪里
为什么在下面两个页面中document.documentElement.clientWidth和document.body.clientWidth两个属性的值返回的正好相反。
HTML code

<!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" />
</head>
<body>

            <a class="mark" onclick="alert(document.documentElement.clientWidth+':'+document.body.clientWidth)">登录</a> 

</body>

</html>


第二个页面
HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>迅雷看看--中国最高清的在线影院</title>
<link href="kankan_2_9.css" rel="stylesheet" type="text/css" />
<script src="kankan_index_2_9.js" type="text/javascript" language="JavaScript"></script>
</head>
<body>

            <a class="mark" onclick="alert(document.documentElement.clientWidth+':'+document.body.clientWidth)">登录</a> 

</body>



请各位高手,<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
代码具体起到了,怎样的作用呢。

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
加了他以后 执行了dtd
必须document.documentElement.clientWidth
内容可见的宽度
------解决方案--------------------
document.documentElement和document.body的区别好像就在html文件是否使用了dtd吧
一个在没有使用dtd下使用 一个在另一情况下使用
------解决方案--------------------
W3C标准哈
就必须执行他咯