第一先实现点击任何地方都隐藏该元素(假设id="bar")$(document).click(function(){$("#bar").hide();});那么bar也属于document,点击bar也会让自己隐藏,显然这不是想要的,这时候要阻止冒泡事件,即document的事件对bar无效$("#bar").click(function(event){event.stopPropagation();});