如何修改粘贴文本? [英] How can I modify pasted text?
本文介绍了如何修改粘贴文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以拦截和修改粘贴到textarea的文本?
Is it possible to intercept and modify text that gets pasted into a textarea?
如果拦截是不可能的,我可以在粘贴后进行修改吗? (不修改textarea中现有的文本)
If intercepting isn't possible, can I modify it after being pasted? (Without modifying the already present text in the textarea.)
推荐答案
使用jQuery:
jQuery(function($){
$('#your_element').bind('paste', function(event){
event.preventDefault();
var clipboardData = event.originalEvent.clipboardData.getData('text/plain');
console.log(clipboardData);
});
}
});
适用于IE和Webkit。使用Firefox可能需要使用以下功能:
Works in IE and Webkit. With Firefox you might have to use this:
http://intridea.com/2007/12/16/faking-onpaste-in-firefox?blog=company
这篇关于如何修改粘贴文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文