大家好。如何修复错误?
获取所有元素
const items = document.querySelectorAll('.tabItem')
有了这样的记录
if (items[index]) items[index].style.display = 'none'
发誓
Property 'style' does not exist on type 'Element'.
大家好。如何修复错误?
获取所有元素
const items = document.querySelectorAll('.tabItem')
有了这样的记录
if (items[index]) items[index].style.display = 'none'
发誓
Property 'style' does not exist on type 'Element'.
该函数
querySelectorAll
返回一个类型NodeListOf<Element>
,该类型Element
中没有属性style
。因此,我们必须明确指出我们要使用HTMLElement
具有指定属性的类型。