AttachShadow是否可以返回不是#shadow根的#document-fragment?

时间:2019-01-29 17:01:10

标签: javascript google-chrome web-component shadow-dom custom-element

我没有在Chrome中使用polyfill,在某些情况下,我发现自定义元素中的this.shadowRoot#document-fragment而不是#shadow-root

例如,这是我的自定义元素中的一些代码,看看当我将鼠标悬停在调试器中时的内容:

enter image description here

我原本希望看到#shadow-root

是否存在升级过程,因此在短时间内最初#document-fragment还不是#shadow-root

1 个答案:

答案 0 :(得分:1)

shadowRoot属性应始终为#document-fragment / DocumentFragment类型。

按照WHATWG DOM specs

  

接口ShadowRoot:DocumentFragment {

     

readonly属性ShadowRootMode模式;
  只读属性元素主机;

     

};

您应该仅在 Element 窗格中看到#shadow-root

您应该在来源窗格中看到#document-fragment