CustomElementRegistry: get() 方法
CustomElementRegistry 介面的 get() 方法返回先前定義的自定義元素的建構函式。
語法
js
get(name)
引數
name-
自定義元素的名稱。
返回值
給定名稱的自定義元素的建構函式,如果沒有定義具有該名稱的自定義元素,則返回 undefined。
示例
js
customElements.define(
"my-paragraph",
class extends HTMLElement {
constructor() {
let templateContent = document.getElementById("custom-paragraph").content;
super() // returns element this scope
.attachShadow({ mode: "open" }) // sets AND returns this.shadowRoot
.append(templateContent.cloneNode(true));
}
},
);
// Return a reference to the my-paragraph constructor
let ctor = customElements.get("my-paragraph");
規範
| 規範 |
|---|
| HTML # dom-customelementregistry-get-dev |
瀏覽器相容性
載入中…