javascript - Shadow DOM 中的内容可编辑?

标签 javascript contenteditable polymer web-component shadow-dom

我正在尝试为 contenteditable 创建一个 Polymer 元素。

我创建了一个 contenteditable div,位置 this.innerHTML在那里,它变得可编辑。使用 polyfills 都很好,例如在火狐中。但它不适用于带有原生 Shadow DOM 的 Chrome 35。

好吧,它仍然是可编辑的,但都不是document.execCommand也不是 window.getSelection正在工作中。

  • document.execCommand什么也没做。
  • window.getSelection().getRangeAt(0).toString()已定义但为空。
  • 没有显示错误。

  • 所以我无法为选择设置样式。

    有人知道是否可以制作自定义可编辑元素吗?我究竟做错了什么?也许在现代/ future 的网络中还有另一种使用 contenteditable 的方法?

    最佳答案

    根据规范 1对于实现者来说,选择有点开放。它确实提到:

    Accordingly, selections may only exist within one node tree, because they are defined by a single range. The selection, returned by the window.getSelection() method never returns a selection within a shadow tree.

    The getSelection() method of the shadow root object returns the current selection in this shadow tree.


    你试过影子根的getSelection() ?

    关于javascript - Shadow DOM 中的内容可编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882272/

    相关文章:

    javascript - 将节点与中断标签一起附加到文档片段

    html - Safari : Text in contenteditable div with no spaces does not wrap around image upon focus

    javascript - 区分自定义 HTML 元素和 native HTML 元素

    javascript - 在 Polymer 1.0 中实现全局变量

    polymer - 有没有办法控制 CustomElementRegistry 和 "dom-module"以外的名称

    javascript - 使用 native Javascript 获取在样式表中设置的 CSS 样式

    javascript - 将多个依赖数据集拟合到 AngularJs ng Repeat 中

    javascript - 了解 http ://urban-walks. com/#map 中使用的拖动 map 功能

    javascript - Foundation 6 change.zf.slider 事件未触发

    html - Contenteditable表格行、列修饰符