0

我正在使用jHtmlArea从用户那里获取一些 HTML,一切都很好,但是当我尝试从其他网站粘贴一些文本时,它不会将换行符解码为<br/>它们在框中。这只发生在粘贴的文本中,手动输入的文本很好。

因此,当我想正确显示文本时,我会使用以下内容:

@Html.Raw(Model.Text.Replace(Environment.NewLine, "<br/>"))

但是当我需要在 jHtmlArea 中重新显示相同的文本以供用户编辑时,它会丢失所有换行符。有谁知道如何解决这一问题?

4

1 回答 1

0

我最后放弃了使用它,有太多的错误我没有时间修复..无论如何,这是我所做的让保存的文本用换行符正确显示(请在保存之前检查源是否良好如果您打算使用此“hack”,请将其发送给 db)

$(document).ready(function () {

//Initialize JhtmlArea 

    $(".editor").htmlarea({
        toolbar: [
                    ["bold", "italic", "underline"],
                    ["orderedList", "unorderedList"],
                    ["link", "unlink"],
                 ]
    });

//Set id (id will be same for all instances)

    $("iframe").attr("id", "editor");

// Style hack

$("#editor").contents().find('body').css({ "font-family": "MS Shell Dlg", "font-size": "12px", "font-weight": "100" });

// Finally to newlines hack

 var html = $(".editor").htmlarea("toHtmlString");

 // I would od something like $(".editor").htmlarea("html", "");
 // But there is a bug since this function calls "pastHtml" internally 
 // which is a typo instead of
 // "pasteHtml" so it won't work

 $("#editor").contents().find('body').html("");
 $(".editor").htmlarea("pasteHTML", html.replace(/\n/g, '<br\>'));


});
于 2012-07-12T15:51:25.523 回答