ajax – 在GWT中点击?

前端之家收集整理的这篇文章主要介绍了ajax – 在GWT中点击?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用GWT构建一个 AJAX Web应用程序,我想使用右键单击各种内容,就像在桌面应用程序中一样.但是,右键单击会生成标准Web上下文菜单,并且永远不会调用void onClick(ClickEvent事件).有没有人想出如何让这个工作?谢谢!
容易腻,在contextmenuhandler上添加一个监听器,它将根据用户右键单击的位置显示一个小部件. https://confluence.clazzes.org/pages/viewpage.action?pageId=425996
  1. class MyWidget extends Composite implements ContextMenuHandler {
  2.  
  3. // just an example,use a meaningful Widget here...
  4. private Widget base;
  5.  
  6. private PopupPanel contextMenu;
  7.  
  8.  
  9. public MyWidget() {
  10. // initialize base widget,etc...
  11.  
  12. this.contextMenu = new PopupPanel(true);
  13. this.contextMenu.add(new HTML("My Context menu!"));
  14. this.contextMenu.hide();
  15.  
  16. initWidget(this.base);
  17.  
  18. // of course it would be better if base would implement HasContextMenuHandlers,but the effect is the same
  19. addDomHandler(this,ContextMenuEvent.getType());
  20. }
  21.  
  22.  
  23. public void onContextMenu(ContextMenuEvent event) {
  24. // stop the browser from opening the context menu
  25. event.preventDefault();
  26. event.stopPropagation();
  27.  
  28.  
  29. this.contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),event.getNativeEvent().getClientY());
  30. this.contextMenu.show();
  31. }
  32.  
  33. }

最后,您将要禁用浏览器菜单以完全重载此类上下文菜单.除了opera之外,这应该适用于所有浏览器.但老实说,这几天新人使用了^ _______ ^

  1. <body oncontextmenu="return false;">

猜你在找的Ajax相关文章