如何获取html所以它不编码?

时间:2010-04-15 13:07:23

标签: javascript jquery

我正在使用javascript获取 fckeditor 的值,以在对话框中显示为预览。现在我希望它显示html标签,就像我输入它们,但它显示我这个

<p>&lt;div&gt;test&lt;/div&gt;</p>

<div>test</div>

我使用以下代码

function test() {
        var oEditor = FCKeditorAPI.GetInstance('FCKeditor1');
        var pageValue = oEditor.GetHTML(true);

        alert(pageValue);            
    }

我尝试更改

等设置
FCKConfig.HtmlEncodeOutput = false;
FCKConfig.ProcessHTMLEntities = true;
FCKConfig.FormatSource = false;

没有运气。我现在对这个问题感到有点沮丧。 有谁知道为什么?

2 个答案:

答案 0 :(得分:1)

为什么不使用DOM?

function unescapeHTML(html) {
    var htmlNode = document.createElement("div");
    htmlNode.innerHTML = html;
    if(htmlNode.innerText)
    return htmlNode.innerText; // IE
   return htmlNode.textContent; // FF
}

source

答案 1 :(得分:-1)

@Pointy是的,我做到了。解决了这个问题。

.replace(/\&lt;/g, '<').replace(/\&gt;/g, '>')