【问题标题】:jHtmlArea not handling paste newlinesjHtmlArea 不处理粘贴换行符
【发布时间】:2012-07-12 15:02:32
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c# asp.net-mvc jhtmlarea


    【解决方案1】:

    最后我放弃使用它,有太多的错误,我没有时间修复.. 无论如何,这是我为使保存的文本正确显示换行符所做的(如果您打算使用此“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\>'));
    
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 2021-04-28
      相关资源
      最近更新 更多