<HTML>
<script>
function divcenter(){
document.all.mxh.style.top=(document.body.clientHeight-100).toString()+"px"
}
</script>
<body onload="divcenter()" onresize=divcenter()>
<table width=100%>
<tr>
<td>test
</td>
</tr>
</table>
<div id=mxh style="position:absolute;left:0;top:0px;width:100%;height:100;background-color:#0099FF;border:2px">测试文字</div>
</HTML>
<script>
function divcenter(){
document.all.mxh.style.top=(document.body.clientHeight-100).toString()+"px"
}
</script>
<body onload="divcenter()" onresize=divcenter()>
<table width=100%>
<tr>
<td>test
</td>
</tr>
</table>
<div id=mxh style="position:absolute;left:0;top:0px;width:100%;height:100;background-color:#0099FF;border:2px">测试文字</div>
</HTML>
你的最终目的是什么?
为了使div1即使在填充了内容以后仍然不会致使(Body)出现滚动条?还是其他什么目的?
<script>
function divcenter(){
document.all.mxh.style.top=(document.body.clientHeight-100).toString()+"px"
}
</script>
<body>
<input type="button" value="c" onclick="divcenter()">1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>
<input type="button" value="c" onclick="divcenter()">1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>
<input type="button" value="c" onclick="divcenter()">
<div id=mxh style="position:absolute;left:0;top:0px;width:100%;height:100;background-color:#0099FF;border:2px">测试文字</div>
</HTML>孟子我把你的那个改了一下,按第一个按钮可以调整位置但按第二个的时候div却没有跟下来。
我的意思是不管滚动条滚到哪里,按某个按钮的时候,div都出现在屏幕顶端下100象索的地方
function divcenter(){
mxh.style.pixelTop = document.body.clientHeight - 100 + document.body.scrollTop;
}