需要 Pure/jQuery Javascript 解决方案来清除文本区域中的 Word HTML [英] Need Pure/jQuery Javascript Solution For Cleaning Word HTML From Text Area

查看:28
本文介绍了需要 Pure/jQuery Javascript 解决方案来清除文本区域中的 Word HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里已经提到了这个问题,但我还没有找到适合我的情况的可行解决方案,所以我想让智囊团恢复工作,看看可以做些什么.

I know this issue has been touched on here but I have not found a viable solution for my situation yet, so I'd like to but the brain trust back to work and see what can be done.

我有一个表单中的文本区域,需要检测何时将某些内容粘贴到其中,并清除所有隐藏的 HTML &引号.此表单的内容会通过电子邮件发送到特别讨厌的 3rd 方系统,因此有时甚至将其编码为 html 实体字符也不是一个安全的赌注.

I have a textarea in a form that needs to detect when something is pasted into it, and clean out any hidden HTML & quotation marks. The content of this form is getting emailed to a 3rd party system which is particularly bitchy, so sometimes even encoding it to the html entity characters isn't going to be a safe bet.

不幸的是,我不能使用像 FCKEditor、TinyMCE 等的东西,在这种情况下它必须保持常规的 textarea.我试图从 word 函数中剖析 FCKEditor 的粘贴,但没有找到它.

I unfortunately cannot use something like FCKEditor, TinyMCE, etc, it's gotta stay a regular textarea in this instance. I have attempted to dissect FCKEditor's paste from word function but have not had luck tracking it down.

不过,如果需要,我可以使用 jQuery 库,但还没有找到用于此的 jQuery 插件.

I am however able to use the jQuery library if need be, but haven't found a jQuery plugin for this just yet.

我专门寻找用于清理粘贴信息的信息,而不是如何监控元素的内容更改.

I am specifically looking for information geared towards cleaning the information pasted in, not how to monitor the element for change of content.

非常感谢任何建设性的帮助.

Any constructive help would be greatly appreciated.

推荐答案

我正在看 David Archer 的回答,他几乎给出了答案.我过去使用过类似于他的解决方案:

I am looking at David Archer's answer and he pretty much answers it. I have used in the past a solution similar to his:

$("textarea").change( function() {
    // convert any opening and closing braces to their HTML encoded equivalent.
    var strClean = $(this).val().replace(/</gi, '&lt;').replace(/>/gi, '&gt;');

    // Remove any double and single quotation marks.
    strClean = strClean.replace(/"/gi, '').replace(/'/gi, '');

    // put the data back in.
    $(this).val(strClean);
});

如果您正在寻找一种完全删除 HTML 标签的方法

If you are looking for a way to completely REMOVE HTML tags

$("textarea").change( function() {
    // Completely strips tags.  Taken from Prototype library.
    var strClean = $(this).val().replace(/</?[^>]+>/gi, '');

    // Remove any double and single quotation marks.
    strClean = strClean.replace(/"/gi, '').replace(/'/gi, '');

    // put the data back in.
    $(this).val(strClean);
});

这篇关于需要 Pure/jQuery Javascript 解决方案来清除文本区域中的 Word HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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