捕捉粘贴输入 [英] Catch paste input

查看:138
本文介绍了捕捉粘贴输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种清理粘贴到浏览器中的输入的方法,这可能与jQuery有关吗?

I'm looking for a way to sanitize input that I paste into the browser, is this possible to do with jQuery?

到目前为止,我已经设法解决了这个问题:

I've managed to come up with this so far:

$(this).live(pasteEventName, function(e) {
 // this is where i would like to sanitize my input
 return false;
}

不幸的是,由于这个小问题",我的发展陷入了停顿. 如果有人能指出正确的方向,我真的会让我成为一个快乐的露营者.

Unfortunately my development has come to a screeching hold because of this "minor" issue. I would really make me a happy camper if someone could point me to the right direction.

推荐答案

我使用以下代码对其进行了修复:

I sort of fixed it by using the following code:

$("#editor").live('input paste',function(e){
    if(e.target.id == 'editor') {
        $('<textarea></textarea>').attr('id', 'paste').appendTo('#editMode');
        $("#paste").focus();
        setTimeout($(this).paste, 250);
    }
});

现在,我只需要存储插入符号的位置并追加到该位置,就可以完成所有操作……我想:)

Now I just need to store the caret location and append to that position then I'm all set... I think :)

这篇关于捕捉粘贴输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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