English 中文(简体)
如何探测单击窗外窗口
原标题:How to detect click outside window

我在 html 代码“ ul” 和“ li” 中有一个定制的下调, 当用户点击“ ul” 头时, 我显示选项, 当用户点击菜单区域外时, 我想隐藏这些元素 。

诸如此类的事情有可能 与 Javascript/YUI 不是Jquery?

最佳回答

我不是UI的人,所以我猜这个可能写得更好 但我已经测试过了,效果也不错

单击文档时隐藏下调 :

Y.one(document).on("click", function(){
    Y.one("#menu").hide(); 
});

防止点击 ul 从传播到 document :

Y.one("#menu").on("click", function(e){
    e.stopPropagation();    
});

如果访问者单击任何地方, 点击会泡到 < code> document 上, 并隐藏菜单。 如果他们点击菜单, 事件将无法泡到 < code> document 上, 因此菜单不会隐藏 。

网站:http://jsfiddle.net/nHnZT/" rel="nofolp">http://jsfiddle.net/nHnZT/

问题回答

use(事件外出) 增加对“外外”活动的支持。 详情请见用户指南 : http://yyyilibrary.com/yui/docs/event/outside. html





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签