IE onpaste JavaScript事件 [英] IE onpaste JavaScript event

查看:125
本文介绍了IE onpaste JavaScript事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我做什么,在取消粘贴"事件后,都无法让IE选择()中的值.

No matter what I do, I can't get IE to select() the value in a after a "paste" event in canceled.

在IE中查看此URL,然后将任何内容粘贴到文本区域:

Look at this URL in IE, and paste anything into the textarea:

http://jsfiddle.net/cfApa/1/

粘贴后应选择文本.这在Chrome中有效,但即使在IE中,我也无法弄清楚在取消粘贴时如何使select()工作:

The text should be selected after pasting. This works in Chrome, but can't figure out how to get select() to work when i'm canceling the paste even in IE:

推荐答案

尝试一下:

$('textarea').on('paste', function(e) {
    this.value = 'fooo';
    setTimeout(function(){ $(e.target).select(); }, 0);

    return false; 
});

不要问我为什么它起作用,我只是好奇并找到了解决方案.

Don't ask me why it works, I just got curious and found a solution.

似乎在粘贴事件处理程序的上下文中选择仅不起作用,之后取消选择的浏览器中可能会发生某些事情(尽管preventDefault仍然无济于事)

It seems that selecting just doesn't work in the context of the paste event handler, maybe there's something that happens afterwards in the browser that deselects (though preventDefault still didn't help)

这篇关于IE onpaste JavaScript事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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