A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/API/Window/customElements below:

Window.customElements - Web API | MDN

Window.customElements

Baseline Widely available

customElements 是 Window 对象上的一个只读属性,接口返回一个 CustomElementRegistry 对象的引用,可用于注册新的 custom element,或者获取之前定义过的自定义元素的信息。

例子

这个属性最常用的例子是用来获取使用CustomElementRegistry.define()方法定义和注册的自定义元素,例如:

let customElementRegistry = window.customElements;
customElementRegistry.define("my-custom-element", MyCustomElement);

However, it is usually shortened to something like the following:

customElements.define(
  "element-details",
  class extends HTMLElement {
    constructor() {
      super();
      const template = document.getElementById(
        "element-details-template",
      ).content;
      const shadowRoot = this.attachShadow({ mode: "open" }).appendChild(
        template.cloneNode(true),
      );
    }
  },
);

参阅我们的 web-components-examples 获取更多有用的例子。

规范 浏览器兼容性

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4