我的问题是风格是:
错误TS2339:类型"NodeListOf"上不存在属性"style
所有的细节都在下面解释.所有的html/css都可以,但只是"返回"不工作
HTML:
这是我的portfolio的一个元素.而且我想在点击时播放一个视频
待办事项列表
带有React的待办事项列表
播放视频
我的代码在 typescript :
从"@angular/core "导入{组件};
@Component ({选择器:'应用程序组合',模板URL:'./portafolio.component.html',样式URL:[./portafolio.component.css'],})导出类portafolioComponent {
constructor() {
const button = document.querySelectorAll('#btn');
const close = document.querySelectorAll('#close');
const videoContent = document.querySelectorAll('#videoContent');
button.addEventListener('click', () => {
videoContent.style.visibility = 'visible';
videoContent.style.opacity = 1;
});
close.addEventListener('click', () => {
videoContent.style.visibility = 'hidden';
videoContent.style.opacity = 0;
});
}
}
我不是Maven,但我想学打字,我不知道我的错误在哪里。
我的tsconfig.json:"目标":"ES2022","模块":"ES2022",
1条答案
按热度按时间7fyelxc51#
querySelectorAll
用于选择多个元素,对于单个元素,应使用querySelector
。querySelectorAll
在TypeScript中的输出类型是NodeListOf<Element>
,而querySelector
在JavaScript中的输出类型是Element or null
。在TypeScript中,它的类型为
Element | null
。在
Element
上,您有style属性。