jQuery click()事件包含所有内容? [英] jQuery click() event catch-all?
本文介绍了jQuery click()事件包含所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在屏幕上显示了一个框,当用户单击屏幕上的任意位置(包括主体,锚点,div,按钮等)时,我想隐藏该框.是否有一个选择器可以为我处理?还是$('body, a, div, input').click()
的情况?
we're showing a box on the screen that I want to hide when the user clicks anywhere on the screen, including body, anchors, divs, buttons, etc... Is there a selector that can handle this for me? Or is it a case of $('body, a, div, input').click()
?
推荐答案
您可以这样做:
$(document).click(function() {
$("#boxID").hide();
});
由于默认情况下click
事件将冒泡到
Since the click
events will, by default, bubble up to document
, this is a "catch all" approach...if you don't want clicks from inside the box to close it, add a .stopPropagation()
call on those click
events like this:
$("#boxID").click(function(e) {
e.stopPropagation();
});
这篇关于jQuery click()事件包含所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文