在Jquery中如何处理粘贴?(复制)

时间:2022-10-05 23:52:42

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. 格式粘贴值
  3. append to textarea
  4. 添加到文本区域

could that be done in Javascript?

这能用Javascript实现吗?

1 个解决方案

#1


12  

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 data and than manipulate it.

事件的问题,它告诉你它即将发生,但是它没有告诉你用户正在粘贴什么。JavaScript限制了对剪贴板的处理,默认情况下它是禁用的。如果允许访问,您可以读取剪贴板数据,而不是操作它。

#1


12  

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 data and than manipulate it.

事件的问题,它告诉你它即将发生,但是它没有告诉你用户正在粘贴什么。JavaScript限制了对剪贴板的处理,默认情况下它是禁用的。如果允许访问,您可以读取剪贴板数据,而不是操作它。