弹出一个对话框,要求点击除该对话框外的任意地方,关闭对话框
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选择指定元素外的其他所有元素</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
border: 1px solid red;
overflow: hidden;
}
.box > div{
height: 100px;
width: 100px;
background-color: cadetblue;
float: left;
margin-left: 10px;
}
.box > div > div{
height: 50px;
width: 50px;
background-color: coral;
}
</style>
</head>
<body>
<div class="box">
<div class="num1">
<div></div>
</div>
<div class="num2">
<div></div>
</div>
<div class="num3">
<div></div>
</div>
</div>
<script type="text/javascript" src="js/jquery-1.11.0.js" ></script>
<script>
$(document).click(function(e){
if( $(e.target).closest('.num2').length == 0 ){
alert("事件触发");
}
});
</script>
</body>
</html>