我有一个jQuery令牌Tagit插件,我想绑定到Paste事件以正确添加项目.
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?
我有一个jQuery令牌Tagit插件,我想绑定到Paste事件以正确添加项目.
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
函数访问粘贴的数据.
$("#textareaid").bind("paste", function(e){
// access the clipboard using the api
var pastedData = e.originalEvent.clipboardData.getData('text');
alert(pastedData);
} );
请注意,从jQuery 3开始,bind和unbind就被弃用了.首选的电话是on.
All modern day browsers support the Clipboard API.