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.
实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mode Chrome 57 Edge 79 Firefox 63
63
不支持 59 — 63 Disabled
Disabled ). To change preferences in Firefox, visit
IE No Opera 40 Safari 10.1 WebView Android 57 Chrome Android 57 Firefox Android 63
63
不支持 59 — 63 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 41 Safari iOS 10.3 Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: