jQuery绑定到Paste Event,如何获取粘贴的内容 [英] jQuery bind to Paste Event, how to get the content of the paste

查看:1818
本文介绍了jQuery绑定到Paste Event,如何获取粘贴的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery令牌tagit插件,我想绑定到粘贴事件以正确添加项目。

I have a jquery token tagit plugin and I want to bind to the paste event to add items correctly.

我能够像粘贴事件一样绑定所以:

I'm able to bind to the paste event like so:

    .bind("paste", paste_input)

...

function paste_input(e) {
    console.log(e)
    return false;
}

如何获取实际粘贴的内容值?

How can I obtain the actual pasted content value?

推荐答案

有一个onpaste事件可以在现代浏览器中使用。您可以使用 clipboardData 对象上的 getData 函数访问粘贴的数据。

There is an onpaste event that works in modern day browsers. You can access the pasted data using the getData function on the clipboardData object.

$("#textareaid").bind("paste", function(e){
    // access the clipboard using the api
    var pastedData = e.originalEvent.clipboardData.getData('text');
    alert(pastedData);
} );

请注意绑定解除绑定自jQuery 3开始不推荐使用。是

Note that bind and unbind are deprecated as of jQuery 3. The preferred call is to on.

所有现代浏览器支持剪贴板API

请参阅另外:在Jquery中如何处理粘贴?

这篇关于jQuery绑定到Paste Event,如何获取粘贴的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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