<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript" src="js/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或其子元素。。这里可以更改其他的内容
/*if ( $('#side_shop_cart').hasClass('sh-hi') ) {
$('.shop-car-sider').animate({left:'35px',opacity:'hide'},'normal',function(){
$('.shop-car-sider').removeClass('sh-hi');
});
}*/
}); </script> </head> <body> <div id="test" style=" 300px; height: 300px; background-color: #CBC7BC;"> div测试内容,点击其它地方会隐藏此div模块。 </div> </body> </html>