2
嗨我试图访问所选元素的子节点,但浏览器告诉我,该对象没有foreach函数。我应该如何为我访问子元素。我不想使用jquery,而是想使用本机,以用于实验目的。Javascript对象forEach不是函数
这里是我的代码:
var el = document.querySelector('ol');
el.children.forEach(function(childEl) {
console.log(childEl);
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<ol contenteditable oninput="">
<li>press enter</li>
</ol>
</body>
</html>
'foreach'是无效的功能,使用'forEach' *资本E *,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ forEach – Tushar
@Tushar nope它不起作用 – loki9