1、将下面两个div放到body中的任意位置
a标签用来显示弹出框
<div class="popFrame">
<a href="#">ddddddddddd</a>
</div>
<div class="shade"></div>
<a id="btn">显示弹出框</a>
2、上面div 的样式
.shade{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.55);
position: absolute;
float: left;
top: 0;
left: 0;
display:none;
}
.popFrame{
width:400px;
height:400px;
background:#fff;
border:1px solid #ccc;
top:20%;
left:36%;
position:absolute;
display:none;
}
3、javascript代码
$(function(){
//获取页面的宽度 高度 即 遮罩的高度和宽度
var height = $(document).height();
var width = $(document).width();
//获取页面中最大的z-index
var maxZ = Math.max.apply(null,$.map($('body > *'),function(e,n){if($(e).css('position') == 'absolute')return parseInt($(e).css('z-index')) || 1;}));
$('div.zhezhao').css({'width':width,'height':height,'z-index':maxZ+1});
$('div.tanchuan').css({'z-index':maxZ+2});
$('#btn').click(function(){
$('div.shade').show();
$('div.popFrame').show();
});
});
可以看到 div.popFrame中的a标签是可以点击的页面中的其他标签都在遮罩的后面不能触发事件