[英]gwt click event document
i need to register a cross platform and version independent click event to the document. 我需要在文档中注册一个跨平台和版本无关的点击事件。 that means i have a two text box and submit button but when i click outside of the two text box and submit button then alert will be displayed .how can i achive this by gwt 这意味着我有一个两个文本框和提交按钮,但当我点击两个文本框外面并提交按钮,然后将显示警报。我可以通过gwt实现这一点
document.get().addMouseClick ??? document.get()。addMouseClick ???
The easiest way that comes to mind is to wrap everything in a FocusPanel
: 想到的最简单方法是将所有内容包装在FocusPanel
:
ClickHandler clickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("TextBox/Button clickHandler.");
event.stopPropagation(); // The important line - We stop the event
// propagation here so that the FocusPanel
// doesn't get the event
}
};
TextBox textBox = new TextBox();
textBox.addClickHandler(clickHandler);
Button button = new Button("Test");
button.addClickHandler(clickHandler);
// Since FocusPanel is a SimplePanel, it can only have one child, so we are
// wrapping everything additionally in a HorizontalPanel
HorizontalPanel hPanel = new HorizontalPanel();
hPanel.add(textBox);
hPanel.add(button);
FocusPanel focusPanel = new FocusPanel(hPanel);
focusPanel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Outside."); // Clicked outside of the TextBox/Button
}
});
RootPanel.get().add(focusPanel);
The downside is that you need to assign ClickHandler
s to every element you don't want an alert for (you can use the same ClickHandler
for that to save memory - like I did above). 缺点是您需要将ClickHandler
分配给您不希望发出警报的每个元素(您可以使用相同的ClickHandler
来保存内存 - 就像我上面所做的那样)。 Other than that, the FocusPanel
implementation should ensure that the onclick behavior stays cross-browser. 除此之外, FocusPanel
实现应该确保onclick行为保持跨浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.