【发布时间】:2019-03-23 11:15:23
【问题描述】:
我正在尝试使用阴影制作自定义元素,但是当我添加阴影时,元素的内容不会呈现。这是我的代码:
JavaScript:
class CustomElement extends HTMLElement {
constructor (){
super();
var shadow = this.attachShadow({mode: 'open'});
var content = document.createElement("DIV");
content.innerText = "hello world";
shadow.appendChild(content);
}
}
customElements.define("custom-element", CustomElement);
HTML:
<custom-element>blah blah blah</custom-element>
但它呈现的只是文本“hello world”
【问题讨论】:
-
codepen.io/Utsav91/pen/eXxmdZ?&editable=true 在 codepen 上它可以工作,但我已经删除了我的答案。
标签: javascript html shadow-dom custom-element