upgrade() 方法在 CustomElementRegistry interface upgrades all shadow-containing custom elements in a 节点 subtree, even before they are connected to the main document.

句法

customElements.upgrade(root);
					

参数

root
节点 instance with shadow-containing descendant elements that are to be upgraded. If there are no descendant elements that can be upgraded, no error is thrown.

返回值

Void.

范例

Taken from the HTML spec :

const el = document.createElement("spider-man");
class SpiderMan extends HTMLElement {}
customElements.define("spider-man", SpiderMan);
console.assert(!(el instanceof SpiderMan)); // not yet upgraded
customElements.upgrade(el);
console.assert(el instanceof SpiderMan);    // upgraded!
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'customElements.upgrade()' in that specification.
实时标准 初始定义。

浏览器兼容性

The compatibility table on 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
upgrade Chrome 68 Edge 79 Firefox 63 IE 不支持 No Opera 55 Safari ? WebView Android 68 Chrome Android 68 Firefox Android 63 Opera Android 48 Safari iOS ? Samsung Internet Android 10.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

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

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

元数据

  • 最后修改: