[英]Click event not firing on label in GWT
I have created a click handler on a gwt label, but it fails to fire. 我在gwt标签上创建了一个点击处理程序,但是无法触发。 Whats wrong?
怎么了? Same method works for other widgets like icon etc.
同样的方法适用于其他小部件,例如图标等。
@UiField Label fileName;
---
---
public void addClickHandler() {
fileName.sinkEvents(Event.ONCLICK);
handler = this.addHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
event.preventDefault();
event.stopPropagation();
Window.alert("UI clicked");
}
}, ClickEvent.getType());
}
As I pointed out in comment. 正如我在评论中指出的那样。 Reason why it is not working is because you are adding native event handler to
this
, and as i but you need to sink DOM events on element to be able to handle them. 它不起作用的原因是因为您正在向
this
添加本机事件处理程序,并且像我一样,但是您需要将DOM事件下沉到element上才能处理它们。 As you did not do this for this
element but for Label
it won't work. 因为您没有
this
元素执行此操作,但对于Label
却不起作用。
As You want to handle click element on Label
, you need to add your handler to fileName
and that will work 因为要处理
Label
上的click元素,所以需要将处理程序添加到fileName
,这将起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.