<script language="javascript">
function switchSpan(spanId)
{
if(document.all[spanId].style.visibility=="visible")
document.all[spanId].style.visibility="hidden";
else
document.all[spanId].style.visibility="visible";document.all[spanId].style.left=document.body.clientWidth/2+document.body.scrollLeft;
document.all[spanId].style.top=document.body.clientHeight/2+document.body.scrollTop;
/*
因为两个按钮之间相隔超过一屏,怎样设置div在屏幕的中央,
如果层拖动改变的位置,怎样雇这个位置?
*/
}
</script>
<input type="button" value="发贴" onclick='switchSpan("post")' ID="Button2" NAME="Button2">
<p>ballack<p>ballack<p>ballack<p>ballack<p>ballack<p>ballack
<p>ballack<p>ballack<p>ballack<p>ballack<p>ballack<p>ballack
<input type="button" value="发贴" onclick='switchSpan("post")' ID="Button3" NAME="Button3">
<div id=post style="position:absolute">发贴<input name=mytext></div>

解决方案 »

  1.   

    非常简单啦!应用动态属性就可以!
    <DIV ID="oDiv"
      STYLE="background-color: #CFCFCF; position: absolute; 
             left:expression(document.body.clientWidth/2-oDiv.offsetWidth/2);
             top:expression(((document.body.clientHeight/2-oDiv.offsetHeight/2)<0)?0:(document.body.clientHeight/2-oDiv.offsetHeight/2))">
    <input type="button" value="发贴" onclick='switchSpan("post")' ID="Button2" NAME="Button2">
    两按钮之间相隔超过一屏
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>><br><br><br><br><br><br><br><br><br><br><br>><br><br><br><br><br><br><br><br><br><br><br>


    <input type="button" value="发贴" onclick='switchSpan("post")' ID="Button3" NAME="Button3"></DIV>