Shadow DOM API的 ShadowRoot接口是一个DOM子树的根节点, 它与文档的主DOM树分开渲染。
属性
ShadowRoot.mode只读- The mode of the
ShadowRoot: either"open"or "closed". - Setting the
modeof a shadow root to "closed" makes the shadow root’s implementation internals inaccessible and unchangeable from JavaScript—in the same way the implementation internals of, for example, the<video>element are inaccessible and unchangeable from JavaScript. ShadowRoot.host只读- A DOM element to which the
ShadowRootis attached. ShadowRoot.innerHTML- The DOM tree inside the
ShadowRoot.
规范
| Specification | Status | Comment |
|---|---|---|
| DOM Interface ShadowRoot |
Living Standard | |
| Shadow DOM the ShadowRoot interface |
Working Draft | Initial definition. |
浏览器兼容性
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | 53 | 未实现[1] | 未实现[2] | 未实现 | 40 | 10 |
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 53 | 未实现[1] | 未实现[2] | 未实现 | 40 | 10.1 |
[1] This feature is not implemented yet. See the Edge platform status.
[2] This feature is implemented behind the preference dom.webcomponents.enabled, defaulting to false. See bug 1205323.