我创建了一个类型为 Typescript 和 html application 的新 Visual Studio 项目,我正在尝试创建一个 shadow dom,但出现错误。
class Append{
element: HTMLElement;
constructor(element: HTMLElement) {
this.element = element;
}
window.onload = () => {
var el = document.getElementById('content');
let shadow = el.attachShadow({mode: 'open'});
}
property attachshadow does not exist on type element
最佳答案
并非所有元素都可以接受 Shadow DOM。
授权的 HTML 元素列表在 attachShadow()
中定义。 Shadow DOM v1 规范中的定义:
valid custom element name,
<article>
,<aside>
,<blockquote>
,<body>
,<div>
,<footer>
,<h1>
,<h2>
,<h3>
,<h4>
,<h5>
,<h6>
,<header>
,<main>
,<nav>
,<p>
,<section>
or<span>
关于javascript - 类型元素上不存在属性 attachshadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51010330/