开发者

Detect click events outside div inside usercontrol

I have a div inside a user control that is displayed by the user after some event.

I want to hide this div when user clicks anywhere elese on the page but not on the div (or not on any element that is inside the div).

If it wasn't a user control I could use body's clieck event to check the target, but because this is usercontrol that is hosted b开发者_StackOverflow中文版y other page I can't just "play" with it's elements.

How can I achieve that without using body of the hosting page?


You certainly can't. But it doesn't matter, because you won't overwrite any existing event handler if you use the addEventListener/attachEvent method instead of the document.body.onclick="..." method.

Here is an example using the Prototype library for easier coding: http://jsfiddle.net/uVt7X/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜