HTML:如何在IE中修改多行复制文本,然后在文本字段中粘贴它 [英] HTML : How to modify multi-line copied text in IE before pasting it in a text field

查看:230
本文介绍了HTML:如何在IE中修改多行复制文本,然后在文本字段中粘贴它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们复制一些由新行分隔的文本并尝试将其粘贴到IE中的文本字段时,文本会从第一个新行字符开始被截断。在Firefox和Chrome中,新行字符只是转换为空格。我需要为所有这些浏览器实现统一的行为。

When we copy some text separated by new line and try to paste it in a text field in IE, the text gets truncated starting from the first new line character. In Firefox and Chrome, the new line character simply converts to a space. I am required to implement a uniform behaviour for all of these browsers.

如果我能掌握复制的文字,我可以将所有 \\ n 转换为 \ n 然后所有 \ n 到空格字符,但我想不出在截断之前访问复制文本的方法

If I can get hold of the copied text, I can convert all \r\n to \n and then all \n to the space character, but I can't think of a way to access the copied text before its truncated

推荐答案

仅适用于IE!您可以从window.clipboardData获取信息,如下所示:

For IE only!! You can get the information from window.clipboardData as shown here:

$('input:text').on('paste', function(ev) {
    var multiCellTarget = $(this);
    setTimeout(function() {
        var cells = window.clipboardData.getData('text').split(/\s+/);
        if (cells.length > 1) {
            // [... do stuff with cells]
        }
    }, 20);
});

20 ms超时是一个解决剪贴板数据似乎不是问题的技巧当jquery开始粘贴事件时可用。

The 20 ms timeout is a trick to work around the problem that the clipboard data does not seem to be available at the time jquery kicks off the paste event.

这篇关于HTML:如何在IE中修改多行复制文本,然后在文本字段中粘贴它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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