.block_opacity{
width: 100%;
height: 100%;
z-index: 1;
opacity: 0.5;
background: #cccccc;
filter: alpha(opacity=50);
top:0;
left: 0;
position: fixed;
display: none;
}
.block{
width: 400px;
height: 300px;
position: absolute;
margin-left: -200px;
margin-top: -150px;
top:50%;
left: 50%;
z-index: 2;
background:red;
display: none;
}
function aa () {
$(".block_opacity,.block").show();
}
$(document).on("click",function(e){
var e=e || window.event;
var target=e.target || e.srcElement;
if(target.id=="bb") return;
$(".block_opacity,.block").hide();
});
//阻止时间冒泡
$("#block").click(function(e){
stopBubble(e);
});
function stopBubble(e){
if (e && e.stopPropagation)
e.stopPropagation();
else
window.event.cancelBubble=true;
}
原文:http://www.cnblogs.com/xiaotaiyang/p/3858595.html