简体   繁体   English

Firefox没有触发粘贴事件

[英]Firefox is not triggering paste event

I am creating application in which I need to bind paste and other events to handle data in a textarea. 我创建的应用程序中需要绑定paste和其他事件以处理文本区域中的数据。

I have 15 rows and 65 cols in my textarea. 我的文本区域中有15行和65个列。

I have created JSFiddle Demo . 我创建了JSFiddle Demo

To produce problem try to follow following steps: 要产生问题,请尝试执行以下步骤:

  1. In first line enter fill it with full 63 characters. 在第一行输入完整的63个字符。
  2. In second line enter only few characters. 在第二行中,仅输入几个字符。
  3. Now in both line try to press ctrl + v. 现在在两行中都尝试按ctrl + v。

In first line console will display only one message. 在第一行控制台中将仅显示一条消息。 ( KeyDown event) KeyDown事件)

In second line console will display two message. 在第二行控制台将显示两个消息。 ( KeyDown and paste event) KeyDownpaste事件)

$('#myTextArea').on('keypress', function(event) {
    console.log('not working');
});

$('#myTextArea').on('paste', function(event) {
    event.preventDefault();
    console.log("Event Fired... Hurray");
});

Please let me know is there any simple way to handle this paste event in all browser. 请让我知道,有没有一种简单的方法可以在所有浏览器中处理此粘贴事件。

您可能想要处理通用事件input ,无论字段如何向其中添加数据,都将触发该事件:

$("#myTextArea").on("input", ...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM