点击页面其他地方的时候,让弹出框消失
<!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">
.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;
}
</style>
</head>
<body>
  <div class="block_opacity" ></div>
  <div class="block" id="block">
  	<input type="text" />
  </div>
  <input type="button" onclick="aa()" value="点击" id="bb" />
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
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;
}
</script>
</body>
</html>
                    
                
                
            
        
浙公网安备 33010602011771号