点击事件被触发,即使没有点击 [英] Click event being fired even not clicking

查看:283
本文介绍了点击事件被触发,即使没有点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,即使我没有点击页面上的任何内容,只是徘徊在页面上,这会触发:

I have this code which fires even if I don't click on anything on the page, just hovering over the page this will trigger:

Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
            @Override
            public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
                switch (event.getTypeInt()) {
                    case Event.ONCLICK:
                        $(".hopscotch-bubble").fadeOut(new com.google.gwt.query.client.Function() {
                            @Override
                            public void f() {
                                JSNIHelper.infoNotify("INFO", "Fade out method invoked!");
                            }
                        });

                }
            }
        });

我不完全确定为什么会发生这种情况,原因是什么?

I am not entirely sure why this happens, what could be the reason?

推荐答案

ClickHandler 在根面板本身上,当页面上的任何位置触发本地点击事件时将被调用。

Add the ClickHandler on the Root Panel itself that will be called when a native click event is fired anywhere on the page.

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.RootPanel;

RootPanel.get().addDomHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
        System.out.println("Click");

    }
}, ClickEvent.getType());

这篇关于点击事件被触发,即使没有点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆