第一个选项:间接调用 forEach
是一个类似数组的对象。使用以下解决方案:parent.children
const parent = this.el.parentElement;
Array.prototype.forEach.call(parent.children, child => {
  console.log(child)
});
is type,它是一个类似数组的对象,因为:parent.childrenNodeList
- 它包含指示节点数的属性
length 
- 每个节点都是一个具有数字名称的属性值,从 0 开始:
{0: NodeObject, 1: NodeObject, length: 2, ...}
 
请参阅本文中的更多详细信息。
第二个选项:使用可迭代协议
parent.children是一个:,它实现了可迭代协议。在 ES2015 环境中,您可以将 与任何接受可迭代的构造一起使用。HTMLCollectionHTMLCollection
与传播操作器一起使用:HTMLCollection
const parent = this.el.parentElement;
[...parent.children].forEach(child => {
  console.log(child);
});
或者使用周期(这是我的首选):for..of
const parent = this.el.parentElement;
for (const child of parent.children) {
  console.log(child);
}