[英]Copy/paste into JS rich-text editor
我正在玩这里介绍的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 </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); "> with </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标签,例如<b>
, <a>
等
或者,粘贴标签剥离的文本。
问题是必须在粘贴到文本编辑器之前完成此操作,因为发送表单后,html标记将与未编辑混合在一起。
大多数所见即所得的编辑器都有HTML的可能性(用html编写)。 检查您的编辑器是否具有它,以及是否确实通过它粘贴了数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.