简体   繁体   English

如何删除RTF区域字段中的HTML标签?

[英]How to remove HTML tags in Rich Text area Fields?

I am using a Rich Text Field, and after entering some data it displays it in HTML font, I have tried Escape : False also but it is not working. 我使用的是RTF文本字段,输入一些数据后,它会以HTML字体显示它,我也尝试过Escape : False但它不起作用。 Here is my code: 这是我的代码:

function GetDescription()
{
    try
    {
        var assetId = '{!JSENCODE(objAsset.Id)}';
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.RemoterAssetDetailView.GetDescription}',
            assetId ,
            function(result, event) {
                if(event.status)
                {
                    var jobjAsset = JSON.parse(result);
                    var strDescription = '';
                    for(var i=0;i<jobjAsset.length;i++)
                    {
                        strDescription +=html_encode(jobjAsset[i][NameSpacePrefix + "DescriptionText__c"]);
                    }
                    j$("#divSpecification").html(strDescription);
                }
                else
                {
                }
            },
            {
                escape: false
            }
        );
    }
    catch(e)
    {
        //alert(e);
    }

A possible answer to your question is this pretty simple function created by @bjornd , which is available right here . 一个可能的答案是@bjornd创建的这个非常简单的函数,可在此处使用 Is function handle the basic HTML special chars, and should solve your problem. 函数处理基本的HTML特殊字符,并应解决您的问题。

EDIT: The escape function has been deprecated, as @Zeke mentionned below. 编辑: escape功能已被弃用,如下所述@Zeke This is not anymore the correct way to do so. 这不再是正确的方法。

If you want to escape special characters from your string, you should use the escape function in Javascript. 如果要从字符串中转义特殊字符,则应使用Javascript中的escape功能。 This function basically converts any special characters, like < or > into their hexadecimal escape sequence. 此函数基本上将任何特殊字符(例如<>转换为十六进制转义序列。

escape('äöü');        // "%E4%F6%FC"

In your case, replace the html_encode(jobjAsset[i][NameSpacePrefix + "DescriptionText__c"]) with escape(jobjAsset[i][NameSpacePrefix + "DescriptionText__c"]) 根据您的情况,将html_encode(jobjAsset[i][NameSpacePrefix + "DescriptionText__c"])替换为escape(jobjAsset[i][NameSpacePrefix + "DescriptionText__c"])

Here is a link of the Mozilla team documentation about this escape function. 这里是一个链接这个Mozilla的团队文档的escape功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM