<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> * emu * </title>
<SCRIPT defer>
<!--
with(document.getElementsByTagName("DIV")[0].style)
{
left = (document.body.offsetWidth-parseInt(width))/2
top = (document.body.offsetHeight-parseInt(height))/2
}
//-->
</SCRIPT>
</head>
<body>
<div style="position:absolute;width=200;height=200;background-color=yellow"></div>
</body></html>

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title> * emu * </title>
    <SCRIPT>
    <!--
    window.onresize = resetDIV;
    function resetDIV()
    {
    with(document.getElementsByTagName("DIV")[0].style)
    {
    left = (document.body.offsetWidth-parseInt(width))/2
    top = (document.body.offsetHeight-parseInt(height))/2
    }
    }
    //-->
    </SCRIPT>
    </head>
    <body onload="resetDIV()">
    <div style="position:absolute;width=200;height=200;background-color=yellow"></div>
    </body>
    </html>这个可以根据页面的变化动态改变层的位置。