javascript 在 Jquery 如何处理粘贴?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7160073/
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-25 23:08:17  来源:igfitidea点击:

In Jquery How to handle paste?

javascriptjquerypaste

提问by Njax3SmmM2x2a0Zf7Hpd

Possible Duplicates:
How do you handle oncut, oncopy, and onpaste in jQuery?
jQuery catch paste input

可能的重复:
您如何处理 jQuery 中的 oncut、oncopy 和 onpaste?
jQuery 捕捉粘贴输入

I have a textarea, on paste to that textarea I want to

我有一个 textarea,粘贴到我想要的那个 textarea

  1. format pasting values
  2. append to textarea
  1. 格式化粘贴值
  2. 附加到文本区域

could that be done in Javascript?

可以在Javascript中完成吗?

回答by epascarello

There is an onpaste event that works in modern day browsers:

有一个适用于现代浏览器的 onpaste 事件:

$("#textareaid").bind("paste", function(){});

Problem with the event, it tells you that it is about to happen, but it doesn't give you what the user is pasting. JavaScript has restricted acccess to the clipboard and by default it is disabled. If the access is enabled you can read the clipboard dataand than manipulate it.

事件有问题,它告诉你它即将发生,但它没有给你用户正在粘贴的内容。JavaScript 限制了对剪贴板的访问,默认情况下它是禁用的。如果启用了访问权限,您可以读取剪贴板数据并对其进行操作。