为了账号安全,请及时绑定邮箱和手机立即绑定

请问如何遍历从getElementsByTagName返回的所有元素

请问如何遍历从getElementsByTagName返回的所有元素

森林海 2020-01-05 11:00:03
我正在尝试遍历getElementsByTagName("input")使用forEach 重构的所有元素。有什么想法为什么在FF,Chrome或IE中不起作用?<html>    <head>    </head>    <body>        <input type="text" value="" />        <input type="text" value="" />        <script>            function ShowResults(value, index, ar) {                alert(index);            }            var input = document.getElementsByTagName("input");            alert(input.length);            input.forEach(ShowResults);    </script>    </body></html>
查看完整描述

3 回答

?
ITMISS

TA贡献1871条经验 获得超8个赞

是的,ES6:


const children = [...parent.getElementsByTagName('tag')];

children.forEach((child) => { /* Do something; */ });

传播操作符的MDN文档(...)


查看完整回答
反对 回复 2020-01-06
  • 3 回答
  • 0 关注
  • 365 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信