日期:2014-05-16  浏览次数:20306 次

怎么在每个div处点击后都显示在屏幕的正中间啊?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
body{
background-color: #9999CC;
}
#ajax{
position: absolute;
background-color: #CCCCCC;
height: 100px;
width: 300px;
z-index: 999;
left: 50%;
top: 50%;
}
</style>
</head>
<body>
<div style="margin-top: 1px;" onclick="ec();">a 1x</div>
<div style="margin-top: 800px;" onclick="ec();">b 800x</div>
<div style="margin-top: 1600px;" onclick="ec();">c 1600x</div>
</body>
<script>
function ec(){
var div=document.createElement("div") 
div.setAttribute("id","ajax");  
var text=document.createTextNode("文本内容");  
div.appendChild(text); 
document.body.appendChild(div);  
}
</script>
</html>


------解决方案--------------------
是当前屏幕的正中间?
------解决方案--------------------
div.style.top = (wh - 100) / 2 + st + "px";//定位
div.style.left = (ww - 300) / 2 + sl + "px"; 

加上 + "px" 在火狐下就可以 其他的没试