我没有在 Chrome 中使用 polyfill,在某些情况下,我看到自定义元素中的 this.shadowRoot
是 #document-fragment
而不是#shadow-root
.
例如,这是我的自定义元素中的一些代码,当我将鼠标悬停在调试器中时,看看它说了什么:
我期待看到 #shadow-root
。
是否有一个升级过程,在一小段时间内,最初 #document-fragment
还不是 #shadow-root
?
最佳答案
shadowRoot
属性应始终为 #document-fragment
/DocumentFragment 类型.
根据 WHATWG DOM specs :
interface ShadowRoot : DocumentFragment {
readonly attribute ShadowRootMode mode;
readonly attribute Element host;};
您应该只在 Element Pane 中看到 #shadow-root
。
您应该在 Sources Pane 中看到 #document-fragment
。
关于javascript - attachShadow 能否返回不是#shadow-root 的#document-fragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54426098/