【问题标题】:Why does what gets pasted into contenteditable change when the div is created in javascript?为什么在 javascript 中创建 div 时粘贴到 contenteditable 中的内容会发生变化?
【发布时间】:2014-11-04 13:26:17
【问题描述】:

代码:http://jsbin.com/mewixajito/2/edit?html,js,console,output

我正在尝试粘贴富文本/html(来自网站/google docs/word)。因此,在示例中,将一些富文本(例如粗体或有颜色的内容)复制到 dynamic = truedynamic = false 的 jsbin 输出中,然后查看区别。

如果你把dynamic改为true,那么粘贴的内容就没有正确的样式,基本上变成纯文本了。

"Lorem Ipsum has been the industry"

如果 dynamic 为 false(使用 html 中的 contenteditable),则粘贴的内容为:

"<span id=\"docs-internal-guid-e65c220d-7af8-1058-1ff7-d7af0ef00ef9\" style='color: rgb(255, 0, 0); font-family: \"Courier New\"; font-size: 11px; font-style: italic; font-variant: normal; font-weight: bold; text-decoration: underline; vertical-align: baseline; background-color: rgb(255, 255, 0);'>Lorem Ipsum has been the industry</span><br>"

我想保留样式化的粘贴内容,但动态创建 div。也许我以错误的方式创建它?

【问题讨论】:

  • 动态添加类而不是样式
  • 你能解释一下你的意思吗?我稍微编辑了问题以使其更清楚。

标签: internet-explorer contenteditable paste


【解决方案1】:

好的,因为它使用的是document.documentElement 而不是普通的document.body

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2017-09-28
    • 2010-11-09
    • 2015-02-28
    • 2017-08-22
    相关资源
    最近更新 更多