我用了个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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.pop{z-index:2;background-color:#FF0000;position:absolute;left:40%;top:40%;width:300px;height:100px;display:none}
-->
</style>
</head> <body style="width:100%;height:100%">
<!--首先设置一个层:-->
<div id="pop1" style="z-index:1;background-color:#CCCCCC;filter: alpha(opacity=80);width:100%;height:100%;position:absolute;left:0px;top:0px;display:none">
</div>
<div id="pop2" class="pop">你好</div>
<!--弹出层的按钮:-->
<button onclick="show('pop1','pop2')">弹出按钮</button>
<script type="text/javascript">
function show(o1,o2){
var o1 = document.getElementById(o1);
var o2 = document.getElementById(o2);
o1.style.display = "block";
o2.style.display = "block";
}
</script>
</body>
</html>
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.pop{z-index:2;background-color:#FF0000;position:absolute;left:40%;top:40%;width:300px;height:100px;display:none}
-->
</style>
</head> <body style="width:100%;height:100%">
<!--首先设置一个层:-->
<div id="pop1" style="z-index:1;background-color:#CCCCCC;filter: alpha(opacity=80);width:100%;height:100%;position:absolute;left:0px;top:0px;display:none">
</div>
<div id="pop2" class="pop">你好</div>
<!--弹出层的按钮:-->
<button onclick="show('pop1','pop2')">弹出按钮</button>
<script type="text/javascript">
function show(o1,o2){
var o1 = document.getElementById(o1);
var o2 = document.getElementById(o2);
o1.style.display = "block";
o2.style.display = "block";
}
</script>
</body>
</html>
方案二: 用js得到网页高度和宽度,并动态更改层的高和宽,设top和left都为0就可 (推荐)
<!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"><!-- http://topic.csdn.net/u/20090407/17/f4e03fe8-7085-441a-91c7-d34b088ca502.html -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档 </title>
<style type="text/css">
<!--
*{padding:0;margin:0}
.pop{z-index:2;background-color:#FF0000;position:absolute;left:40%;top:40%;width:300px;height:100px;display:none}
-->
</style>
</head> <body style="width:100%;height:100%">
<!--首先设置一个层:-->
<div id="pop1" style="z-index:1;background-color:#CCCCCC;filter: alpha(opacity=80);width:100%;height:100%;position:absolute;left:0px;top:0px;display:none">
</div>
<div id="pop2" class="pop">你好 </div>
<!--弹出层的按钮:-->
<button onclick="show('pop1','pop2')">弹出按钮 </button>
<script type="text/javascript">
function show(o1,o2){
var o1 = document.getElementById(o1);
var o2 = document.getElementById(o2);
o1.style.width = document.documentElement.scrollWidth;
o1.style.height = document.documentElement.scrollHeight
o1.style.display = "block";
o2.style.display = "block";
}
</script>
<div style="height:999px;width:2999px;"></div>
</body>
</html>
遗憾的是IE6不支持fixed属性。不过针对IE6的fixed有一些变通方案,Google一下IE6 fixed就看到了