mode
特性为
ShadowRoot
specifies its mode — either
open
or
closed
. This defines whether or not the shadow root's internal features are accessible from JavaScript.
当
mode
of a shadow root is "
closed
", the shadow root’s implementation internals are inaccessible and unchangeable from JavaScript—in the same way the implementation internals of, for example, the
<video>
element are inaccessible and unchangeable from JavaScript.
var mode = shadowRoot.mode
A value defined in the
ShadowRootMode
enum — either
open
or
closed
.
let customElem = document.querySelector('my-shadow-dom-element');
let shadow = customElem.shadowRoot;
// Another way to check whether the shadow root is open; it will return null if not
if(shadow) {
// If it is open, close it to stop people stealing our secrets!
shadow.mode = 'closed';
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'ShadowRoot.mode' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mode
|
Chrome 57 | Edge 79 |
Firefox
63
|
IE No | Opera 40 | Safari 10.1 | WebView Android 57 | Chrome Android 57 |
Firefox Android
63
|
Opera Android 41 | Safari iOS 10.3 | Samsung Internet Android 6.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
ShadowRoot
delegatesFocus
host
innerHTML
mode