可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How do I check for a click on everything but a certain object?
I use (not), but I'm not sure how to call the class / id of the entire page.
$(".page").not("#divInfoBox").click(function (event) { }
What's the correct way in the HTML code to specify page
, as I have something like:
<html> <body> <div class="page"> </div> </body> </html>
What I see is this: Clicking on the top half of the page works; but the bottom of the page, where there is nothing but background color, the click does not register because it is "off the page" -- how do I extend this so the click works everywhere?
Thanks, Michael
回答1:
You can add a click event to the "html" element. That way you get events even if you're "off" the page:
$("html").click( function() { ... } );
Demo can be seen here: http://jsbin.com/eguti
回答2:
Try this:
$("body:not('#divInfoBox')").click(function (event) { });
Read the doc page for the not
selector:
http://docs.jquery.com/Selectors/not
回答3:
Your missing the ); at the end, should be like this:
$(".page").not("#divInfoBox").click(function (event) { // do something });
As for your question, the 'page' div is not extending to the bottom of the page so you need to register the function to work on the body tag.
Also it looks like you are making a popup appear when certain things are clicked and disappear when clicked off to the side. I would recommend looking for a plugin that will handle this for you. I know there are several. Personally I like jqModal.