jQuery实现鼠标点击div外的地方div隐藏消失的效果(转)

转:https://www.cnblogs.com/jsingleegg/p/3456152.html

css部分:

<style type="text/css">
.pop { 200px; height:130px; background:#080;}
</style>

样式与JS部分:

<body>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script type="text/javascript">
    $(function(){
 

      $(document).bind("click",function(e){
          var target  = $(e.target);

                        // 判断有没有这个class
          if(target.closest(".pop").length == 0){
               $(".pop").hide();
            }    
       })
    })
  </script>

<div class="pop"></div>

点击空白的地方指定div 隐藏消失了
</body>

原文地址:https://www.cnblogs.com/zhaobao1830/p/10132368.html