不格式化的JQuery文本编辑器粘贴 [英] JQuery Text Editor Paste Without Formatting

查看:106
本文介绍了不格式化的JQuery文本编辑器粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用插件JQuery Text Editor.有时,当用户将来自另一个网站的预格式化HTML文本复制并粘贴到插件的文本框中时,它将无法正确呈现并中断部分字符串.从数据库中检索后可以看到残破的文本.

I am using the plugin JQuery Text Editor on my site. Sometimes, when users copy and paste preformatted HTML text from another website into the plugin's textbox it will render incorrectly and break off part of the string. The broken text can be seen after retrieval from the database.

如果您手动编写此文本,或从框中复制文本并重新粘贴,则该文本会很好显示.

If you manually write this text, or copy it from the box and repaste it, it will appear fine.

我相信这与JQuery Text Editor的格式错误有关.

I believe this is something to do with incorrect formatting for JQuery Text Editor.

我在下面的Stack上找到了该函数,看起来像它可以工作:

I found this function below on Stack which looks like it would work:

document.querySelector("div[announcements_container]").addEventListener("paste", function(e) {
    e.preventDefault();
    var text = e.clipboardData.getData("text/plain");
    document.execCommand("insertHTML", false, text);
});

但是,问题是,当我使用此代码时,"JQuery文本编辑器"文本框损坏,如下所示:

However, the problem is that when I use this code my JQuery Text Editor textbox breaks as seen below:

JQTE的HTML:

HTML for JQTE:

<textarea class="jqte" style="margin-bottom: -20px;" rows="50" cols="50" name="body" id="body"></textarea>

通常看起来像这样:

有人可以帮我吗?谢谢.

Can anybody help me out? Thanks.

推荐答案

嗯,当我在 jqte 演示页面.它将未格式化的文本粘贴到顶部框中.以防万一,我更改了 execCommand insertText,因为这正是我们想要的.

Hmm, your code snippet seems to work for me when I run this on the jqte demo page. It pastes unformatted text into the top box. Just in case, I changed our execCommand to insertText since that's what we want to anyway.

document.querySelector("div.jqte_green_editor").addEventListener("paste", function(e) {
    e.preventDefault();
    var text = e.clipboardData.getData("text/plain");

    document.execCommand("insertText", false, text);
});

您确定div[announcements_container]的选择器正确吗?也许改为尝试div.announcements_container.

Are you sure your selector of div[announcements_container] is correct? Maybe try div.announcements_container instead.

这篇关于不格式化的JQuery文本编辑器粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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