CustomElementRegistry.upgrade()

您正在阅读此内容的英文版本,因为该语系尚未翻译。 帮助我们翻译此文章吧!

CustomElementRegistry接口的upgrade()方法将更新节点子树中所有包含阴影的自定义元素,甚至在它们连接到主文档之前也是如此。

语法

customElements.upgrade(root);

参数

root
待升级的包含阴影的派生元素节点 。如果没有可升级的派生实例,则不会抛出异常。

返回值

空.

示例

摘至HTML 规范:

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!

规范

Specification Status Comment
HTML Living Standard
customElements.upgrade()
Living Standard Initial definition.

浏览器支持

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
upgrade
Experimental
Chrome Full support 68Edge No support NoFirefox Full support 63IE No support NoOpera Full support 55Safari ? WebView Android Full support 68Chrome Android Full support 68Firefox Android Full support 63Opera Android Full support 48Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.