<html>
<head>
//下面红色的代码放到css文件中
#add_value {
margin-top:10px;
display:none;
z-index:750;
position:fixed;
background-color:#fefefe;
width:600;
border:1px solid #000;
}
<script language="javascript" type="text/javascript">
//关闭
window.onload = function ()
{
var add_close=document.getElementById("add_close");
var add_value=document.getElementById("add_value");
add_close.onclick = function ()
{
add_close.style.display = "none";
add_value.style.display="none";
};
};
//弹层
function show() {
//得到该层
var Idiv = document.getElementById('add_value');
//将该层显示出来
Idiv.style.display = "block";
//确定层的位置
Idiv.style.left = (document.documentElement.clientWidth - Idiv.clientWidth)/2+ "px";
Idiv.style.top = (document.documentElement.clientHeight - Idiv.clientHeight)/2 + "px";
//设置鼠标的滚轮是否滚动
document.body.style.overflow = "scroll";
var oClose = document.getElementById("add_close");
oClose.style.display = "block";
}
</script>
</head>
<body>
<input type="button" value="弹层" οnclick=show()>
<div id="add_value">
<table >
//关闭按钮
<a href="javascript:" id="add_close" style="float:right">[x]</a>
</th>
</table>
</div>
</body>
</html>