代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>区域外点击事件</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
</head>
<style media="screen">
#box{
height:200px;
width:200px;
border:1px solid grey;
text-align: center;
line-height: 200px;
}
</style>
<body>
<div id="box">
区域内
</div>
<script type="text/javascript">
var box = document.getElementById('box');
document.body.onclick = function(e){
e = e || window.event;
var target = e.target || e.srcElement;
if(target != box){
alert("这是区域外了");
}
}
}
</script>
</body>
</html>
效果图