【问题标题】:Copy/paste into JS rich-text editor复制/粘贴到 JS 富文本编辑器
【发布时间】:2012-02-18 12:42:15
【问题描述】:

我正在使用 HERE 介绍的 Ritch-Text Editor 的 mozilla 示例。一切似乎都很好,但是当从网页复制/粘贴简单文本时,它会添加许多不必要的 html 标签。例如,如果复制当前页面的最后一行;可怕的文字将是

        <p><span style="color: rgb(68, 68, 68); font-family: Arial, 'Liberation Sans',
     'DejaVu Sans', sans-serif; font-size: 13px; line-height: 12px; text-align: left;
 background-color: rgb(119, 119, 119); ">site design / logo © 2012 stack exchange
     inc; user contributions licensed under&nbsp;</span><a 
href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license" style="
    margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;
     padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left:
     0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px;
     border-left-width: 0px; border-style: initial; border-color: initial; border-image:
 initial; font-size: 13px; vertical-align: baseline; background-image: initial;
     background-attachment: initial; background-origin: initial; background-clip:
     initial; background-color: rgb(119, 119, 119); color: rgb(68, 68, 68); cursor:
     pointer; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;
     line-height: 12px; text-align: left; ">cc-wiki</a><span style="color:
     rgb(68, 68, 68); font-family: Arial, 'Liberation Sans', 'DejaVu Sans',
     sans-serif; font-size: 13px; line-height: 12px; text-align: left; background-color: 
    rgb(119, 119, 119); ">&nbsp;with&nbsp;</span><a 
    href="http://blog.stackoverflow.com/2009/06/attribution-required/" rel="license" 
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;
     padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;
     border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px;
     border-left-width: 0px; border-style: initial; border-color: initial;
     border-image: initial; font-size: 13px; vertical-align: baseline; background-image:
     initial; background-attachment: initial; background-origin: initial; background-clip: 
initial; background-color: rgb(119, 119, 119); color: rgb(68, 68, 68); cursor: pointer;
     font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 12px;
     text-align: left; ">attribution required</a></p>

这使得文本编辑器实际上毫无用处。如何强制编辑器仅粘贴主要的 html 标签,如 &lt;b&gt;&lt;a&gt;

或者粘贴标签剥离的文本。

问题是这必须在粘贴到文本编辑器之前完成,因为发送表单后,html标签将与out edit混合。

【问题讨论】:

    标签: javascript html forms editor wysiwyg


    【解决方案1】:

    大多数 WYSIWYG 编辑器都有 HTML 可能性(用 html 编写)。 检查你的编辑器是否有它,如果它只是通过它粘贴你的数据。

    【讨论】:

      猜你喜欢
      • 2010-09-30
      • 1970-01-01
      • 2015-07-02
      • 2018-10-26
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      相关资源
      最近更新 更多