标题总结了这一点。
我只是想在单击#test或它的子项之外的任何其他内容时隐藏#test。
发布于 2010-09-15 22:48:41
您可以在这里使用event bubbling,例如:
$("#test").click(function(e) {
e.stopPropagation();
});
$(document).click(function() {
$("#test").hide();
});如果点击来自#test内部,它将通过event.stopPropagation()停止冒泡,如果来自其他任何地方,click将(默认情况下)一直冒泡到document,它有一个.click()处理程序来隐藏#test。
发布于 2010-09-15 23:40:02
可能是这样的:
// http://api.jquery.com/delegate/
// http://api.jquery.com/not-selector/
$("body").delegate("*:not(#test)", "click", function () {
$("#test").hide(); // But would be better to cache $("#test") !
});https://stackoverflow.com/questions/3718796
复制相似问题