var _h=document.body.clientHeight;
var div=document.getElementById("jingdu");
div.style.top=(parseInt(_h)-parseInt(div.offsetHeight))/2;
水平居中
body{text-align:center;width:100%;}
#jingdu{margin:0 auto 0 auto;}
var div=document.getElementById("jingdu");
div.style.top=(parseInt(_h)-parseInt(div.offsetHeight))/2;
水平居中
body{text-align:center;width:100%;}
#jingdu{margin:0 auto 0 auto;}
<SCRIPT LANGUAGE="JavaScript">
<!--
var cc=document.getElementById("cc");
cc.style.marginLeft=-cc.offsetWidth/2;
cc.style.marginTop=-cc.offsetHeight/2;
//-->
</SCRIPT>
保证好用。
<div id="cc" style="position:absolute;top:50%;left:50%;border:1px dotted #F00;width:300px;height:100px"> <span id="asp">asp.netffffffffffffff</span></div>
<SCRIPT LANGUAGE="JavaScript">
<!--
var cc=document.getElementById("cc");
cc.style.paddingLeft=(cc.offsetWidth-document.getElementById("asp").offsetWidth)/2;
cc.style.paddingTop=(cc.offsetHeight-document.getElementById("asp").offsetHeight)/2;
//-->
</SCRIPT>