html如下:
<div class="btn" id="btn">btn</div>
<div class="box"></div>
方法1:
$('.btn').on('click',function(e){
$('.box').show();
e.stopPropagation();
})
$('body').on('click',function(){
$('.box').hide();
});
方法2:
$('body').click(function(e) {
var target = $(e.target);
if(target.is('#btn')){
$('.box').show();
}else{
$('.box').hide();
}
});