说有一个以典型方式定义的自定义HTML元素,另一个是从其继承的:
class CEParent extends HTMLElement { constructor() { super(); } }
class CEChild extends CEParent { constructor() { super(); } }
customElements.define("ce-parent", CEParent);
customElements.define("ce-child", CEChild);
现在假定HTML仅包含对<ce-child></ce-child>
元素的引用。是否可以根据<ce-child>
选择/设置ce-parent
的样式?
赞
ce-parent:and-derived-too {
...
}
?
这会将父元素名称分配为每个元素的CSS类
需要一些字符串处理,因为对于匿名函数,constructor.name
为“”(空字符串)