【发布时间】:2019-07-09 06:55:13
【问题描述】:
我是打字稿的新手,我正在尝试遍历document.getElementsByClassName() 获得的 HTMLCollection。我的代码是:
let tag_list = document.getElementsByClassName("...") as HTMLCollectionOf<HTMLLinkElement>;
for (const tag of tag_list) {
//do sth with tag.href
}
但事实证明“TS2495:类型'HTMLCollectionOf'不是数组类型或字符串类型。”那么我能做些什么来防止这个错误呢?
【问题讨论】:
标签: typescript