我正在尝试为 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/