【发布时间】:2019-01-12 14:20:18
【问题描述】:
我确定我在规范中遗漏了一些基本内容,但是在运行 Safari 的 Mac 上构建了大量自定义元素后,我发现它们不适用于 Firefox 和 Chrome。我错过了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>NoCE</title>
<script>
class NoCE extends HTMLElement {
constructor(args) {
super();
}
connectedCallback() {
this.innerHTML = "<p>It Works</p>";
}
attributeChangedCallback(name, oldValue, newValue, namespaceURI) {}
disconnectedCallback() {}
adoptedCallback() {}
static get observedAttributes() { return []; }
}
customElements.define("no-ce", NoCE, { extends: "div" });
</script>
</head>
<body>
<no-ce>
No custom elements
</no-ce>
</body>
</html>
在 Safari 中,页面显示“It Works”。在 Firefox 和 Chrome 中,它显示“无自定义元素”(在 Mac OS X 上运行。)
Safari 12.0.2 火狐 64.0.2 铬 71.0.3578.98
【问题讨论】:
-
我看到删除 { extends: "div" } 有帮助,但后来我失去了 div 继承。
标签: javascript google-chrome firefox web-component custom-element