在粘贴事件上获取有关文档的粘贴内容 [英] Get the pasted content on document on paste event

查看:91
本文介绍了在粘贴事件上获取有关文档的粘贴内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如问题中所述,我如何获取文档上的粘贴内容。截至目前,我正在创建一个文本区域和dblclick以将焦点转移到textarea,然后在textarea的粘贴事件中我正在收集数据。我不认为这是一个好方法。我的代码在

As mentioned in the Question how can I get the pasted content on document.As of now I am creating a text area and dblclick to get the focus into textarea and then on paste event of the textarea I am collecting the data. I dont think this is a good approach. My code is below

$('body').dblclick(function()
{
      $('#textare').focus();
});

Then 
$('#textare').keyup(function()
{
      alert( $(this).val() );
});

请为我推荐一个替代流程。

我正在寻找替代方案

Please suggest me a alternative process.
I am looking for alternative like

$(document).paste(function()
{
    // Get the pasted content
});

我使用谷歌浏览器浏览器。我不想用textarea来捕捉文字。

I am using google chrome browser. I dont want to use textarea to catch the text.

推荐答案

你可以添加 onpaste 您元素的事件。它受到所有浏览器的支持

you can add onpaste event to your element. It is supported by all the browers

 onpaste="return getPastedValue(this);"


 <script type="text/javascript">
        function getPastedValue (obj) {
            alert(obj.innerHTML);
           return false;
      }
 </script>

这篇关于在粘贴事件上获取有关文档的粘贴内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆