简体   繁体   English

在文档上的右键单击(contextmenu)事件上在popupmenu上创建无法正常工作

[英]Creating on popupmenu on a right-click(contextmenu) event on a document not working as expected

I'm trying to listen to a right-click event on a document, on which a pop-up menu (goog.ui.popupmenu) should be created. 我正在尝试听文档上的右键单击事件,应在该事件上创建一个弹出菜单(goog.ui.popupmenu)。 The very first time, the menu is created on right-click, but after that its created even on left clicks. 菜单第一次是在右键单击时创建的,但此后甚至在单击鼠标左键时也会创建。

I tried detaching the object from the element when the first time event is received. 我尝试在收到第一次事件时从元素分离对象。 But that doesnt seem to work. 但这似乎不起作用。

Here's what I'm doing: 这是我在做什么:

goog.events.listen(element, goog.events.EventType.CONTEXTMENU, function(e) {
     e.preventDefault();
     this.menu();
}, true, this);

I'm testing this code on Chrome. 我正在Chrome上测试此代码。

Your code works fine for me (at least the part which you shared). 您的代码对我来说很好(至少您共享的部分)。 It reacts to the first and every other right click and never reacts to left click. 它对第一次单击和所有其他右键单击做出反应,而对左键单击永远不做出反应。

But you can make the element to react to right click by supplying true as the opt_contextMenu parameter of the attach method, such as like this: 但是您可以通过提供true作为attach方法的opt_contextMenu参数来使元素对右键单击做出反应,例如:

popupMenu.attach(element, goog.positioning.Corner.TOP_LEFT, goog.positioning.Corner.BOTTOM_LEFT, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM