You can tell any click that bubbles all the way up the DOM to hide the dropdown, and any click that makes it to the parent of the dropdown to stop bubbling.
/* Anything that gets to the document
will hide the dropdown */
$(document).click(function(){
$("#dropdown").hide();
});
/* Clicks within the dropdown won't make
it past the dropdown itself */
$("#dropdown").click(function(e){
e.stopPropagation();
});
Demo: http://jsbin.com/umubad/2/edit
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…