javascript - attachShadow 能否返回不是#shadow-root 的#document-fragment?

标签 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

最佳答案

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/

相关文章:

javascript - 主页横幅下方的二级导航

data-binding - 使用 polymer 1.0 在两个 polymer 元素之间进行数据绑定(bind)

polymer - 如何跳过 Shadow DOM(并使用 Light DOM)代替 Polymer 模板

javascript - 自定义 HTMLElement 的 connectedCallback() 中的 textContent 为空

javascript - JSFiddle 代码在我自己的页面中不起作用

python - Selenium - 未找到元素(python)

javascript - Javascript 中对象属性的方法

javascript - CSS height 属性被 for 循环中最后计算的高度参数覆盖

javascript - 没有 getElementById 引用成功的 addEventListener()?

google-chrome - 从 Chrome 存储中获取所有 key