<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <title></title> <script type="text/javascript"> $(document).bind('click', function(e) { var e = e || window.event; //浏览器兼容性 var elem = e.target || e.srcElement; while (elem) { //循环判断至跟节点,防止点击的是div子元素 if (elem.id && elem.id == 'test') { return; } elem = elem.parentNode; } $('#test').css('display', 'none'); //点击的不是div或其子元素 }); </script> </head> <body> <div id="test" style=" 300px; height: 300px; background-color: #CBC7BC;"> <table> <tr> <td>12</td> <td>23</td> </tr> <tr> <td>12</td> <td>23</td> </tr> </table> </div> </body> </html>