Adding a click handler for an html element?

前端 未结 2 1651
情歌与酒
情歌与酒 2021-02-10 19:56

I have a page pregenerated for me using html, it looks like a scrollable list of divs, something like:


  
Item A
2条回答
  •  情歌与酒
    2021-02-10 20:17

    The problem using wrap() is that if the parent element is already a widget, the wrapping is not allowed. You can still do it and will work, but if you run the application in development mode the assertion will fail, stopping the application.

    The right (but tedious and in my opinion incomplete) way is something like

    Element elem = DOM.getElementById(“billing-component”);
    DOM.sinkEvents(elem, Event.ONCLICK | Event.ONMOUSEOUT | Event.ONMOUSEOVER);
    DOM.setEventListener(elem, new EventListener() {
        @Override
        public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
                …
            }
        }
    });
    

    I know doesn't look nice, and actually it isn't because you can only attach a single listener to the element and have to check for the event type.

提交回复
热议问题