粘贴事件多次触发

时间:2013-09-11 12:25:50

标签: javascript jquery gwt errai

这是我处理粘贴事件的Chrome代码:

window.addEventListener("paste",processEvent);
function processEvent(e) {      
       console.log("paste event!");
}

此代码工作正常,但即使我只按CTRL+V命令一次也会多次触发事件。可能是什么原因?我怎样才能防止这种情况发生,因为每次按下粘贴命令时只需触发一次处理程序非常重要。

更新:

我登录到控制台,这就是我的意思:

paste event!
clipboard from event
item found: 0 kind=file type=image/png
found image!
paste event!
clipboard from event
item found: 0 kind=file type=image/png
found image!
paste event!
clipboard from event
item found: 0 kind=file type=image/png
found image!

注意同一事件是如何被触发3次。

更新2:

这段代码实际上是一个围绕JSNI的GWT代码:

public native void pasteEventHandler()/*-{
    window.addEventListener("paste",processEvent);
    function processEvent(e) {      
           console.log("paste event!");
    }
}-*/;

在应用的@PostConstruct期间调用:

@PostConstruct
public void setup() {
     pasteEventHandler();
}

当粘贴事件发生时,“页面”转换到另一个页面(从#Page1到#Page2。当页面转换回#Page1时,setup()方法被激活。

1 个答案:

答案 0 :(得分:1)

好吧,从您的代码中我看到了其他}

window.addEventListener("paste",processEvent);
    function processEvent(e) {      
       console.log("paste event!");
    }
}  // what's that ?

也许}属于forwhile(或其他)迭代。

相关问题