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