页面中有个div,如下: <div id="Menu1" name="Menu1" class="group" style="display:;">
</div>
javascript如下: window.onload = init;
function init()
{
document.getElementById("Menu1").style.height = window.document.body.clientHeight;
}
在IE中能够成功设置div的高度,而在火狐浏览器中就不行,请指教一下,在火狐中应该怎么写?
</div>
javascript如下: window.onload = init;
function init()
{
document.getElementById("Menu1").style.height = window.document.body.clientHeight;
}
在IE中能够成功设置div的高度,而在火狐浏览器中就不行,请指教一下,在火狐中应该怎么写?
<div id="Menu1" name="Menu1" class="group" style="border:solid 1px #000;" >
aaaa
</div>
<script>
window.onload = init;
function init()
{
document.getElementById("Menu1").style.height = window.document.body.clientHeight;
}
</script>
document.getElementById("Menu1").style.height = window.document.body.clientHeight + "px";
楼上所说的可以,是因为window.document.body.clientHeight获取的高度是内容的高度,我看了一下只有20所以看不出效果!JavaScript这样写,大家再试试吧! window.onload = init;
function init()
{
document.getElementById("Menu1").style.height = 400;
}
在IE里面div会变高,而在火狐里面不变!
给 DIV 加上 border:1px solid black 就能看出效果给出详细代码才能找到原因(可能是父容器的height被固定了,所以看不出效果)
在我的FF的没问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
window.onload = init;
function init()
{
document.getElementById("Menu1").style.height = 400;
}
</script>
</head><body>
<div id="Menu1" name="Menu1" class="group" style="border:solid 1px #000;" >
aaaa
</div>
</body>
</html>
{
document.getElementById("Menu1").style.height = "400px";
}
这个是ie 和ff的一个区别,ie是有默认单位的
FF 浏览器onload 注册要用
document.addEventListener("DOMContentLoaded", init, null);
<script>
if(document.all)
{
window.onload = init;
}
else
{
if (document.addEventListener)
{
document.addEventListener("DOMContentLoaded", init, null);
}
}
function init()
{
document.getElementById("Menu1").style.height='400px';
}
</script>
</head><body>
<div id="Menu1" name="Menu1" class="group" style="border:solid 5px #33CCCC;" >
aaaa
</div>
</body>
你如果这样设置 function init()
{
document.getElementById("Menu1").style.height = '400px';
}
就行,你没有把400px 加上字符串标号.
应该说这样也可以的
window.screenTop在IE里面能获取到高度,在FF里面返回的是undefined!
这只能在IE下运行,在火狐下不行.