Mozilla 声明“for of 循环将正确地遍历 NodeList 对象”。 (来源:https://developer.mozilla.org/en-US/docs/Web/API/NodeList)但是,这在 Chrome 43 中不起作用。这是不正确的文档还是浏览器错误?
在带有复选框的页面上使用的复制示例代码:
var list = document.querySelectorAll( 'input[type=checkbox]' );
for (var item of list) {
item.checked = true;
}
最佳答案
编辑:This is shipping in Chrome 51 .
Jake Archibald posted a simple fix :
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]
还有 for of 循环。
关于javascript - for of 循环querySelectorAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836289/