0

我在获取有关 ONPASTE 事件的文本时遇到问题。假设我有 5 个文本框并且我正在使用 sinkEvent 那么我将如何获取将要粘贴到任何文本框中的文本

public abc() {
    super();
    TextBox t1 = new TextBox();
    TextBox t2 = new TextBox();
    TextBox t3 = new TextBox();
    TextBox t4 = new TextBox();
    TextBox t5 = new TextBox();

    sinkEvents( Event.ONPASTE );
}

@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent( event );

    switch (DOM.eventGetType(event)) {
        case Event.ONPASTE:
            //Now here i want to read get the text which is going to be 
            //pasted in the any of the textbox
    }
}
4

1 回答 1

1

您必须在文本框本身中捕获事件。您可以扩展文本框以在 onpaste 事件上触发事件,或者像这样快速而肮脏地进行操作:

public abc() {
    super();
    TextBox t1 = new TextBox(){

        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            checkForPastEventAndDoSomething(event);
        }
    };
    //...
}

private void checkForPastEventAndDoSomething(Event event) {
    switch (event.getTypeInt()) {
                case Event.ONPASTE:
                //Now here i want to read get the text which is going to be 
                //pasted in the any of the textbox
                break;
}
于 2016-02-16T11:33:20.540 回答