javascript 有人复制粘贴时触发keyup功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30325515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:02:52  来源:igfitidea点击:

Trigger the keyup function when someone copy and paste

javascriptjquery

提问by Bekki

I've got a keyup function for multiple text boxes. How do I trigger the keyup function when someone copy and past something in to the textbox?

我有一个用于多个文本框的 keyup 功能。当有人将某些内容复制并粘贴到文本框中时,如何触发 keyup 功能?

.on("click blur keyup", ".emotion", function() {
     //match something
});

回答by mathielo

Switch the event keyupfor input, which will trigger whenever something is inputted into the field, even if text is being pasted (both by pressing CTRL + Vor right mouse button ? Paste.

切换事件keyupfor input,它会在字段中输入内容时触发,即使正在粘贴文本(通过按下CTRL + V或鼠标右键?粘贴。

.on('input', '.emotion', function() {   
    // Do your stuff.
});

回答by Thomas Theunen

This will do what you want:

这将执行您想要的操作:

$("#editor").on('paste', function(e) {
  $(e.target).keyup();
});

$("#editor").on('keyup', function(e) {
  alert('up');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="editor">

回答by Bfcm

Use the pasteevent. As far as I've tested it works for Ctrl+V pasting, and right-click>Paste pasting.

使用paste事件。据我测试,它适用于 Ctrl+V 粘贴,然后右键单击>粘贴。