We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用 document.querySelectorAll 获取到一批 DOM 节点之后,常常需要遍历这些节点,为每个节点绑定对应的事件。
document.querySelectorAll
在 JavaScript closure inside loops – simple practical example 中虽然讲到可以用 forEach、let,但是在部门的 iPhone 4、三星平板这两部旧设备上,无法使用这些新特性。
forEach
let
上网查了一下,在 Using forEach on an array from getElementsByClassName results in “TypeError: undefined is not a function” 中讲到,用 document.querySelectorAll 之类的方法获取到的 DOM 节点,是 HTMLCollection,是“类数组对象”,所以在一些旧设备上,是无法使用 forEach 这样的方法来遍历 DOM 节点的。
最保险的方法,就是采用最原始的 for 循环来遍历这些 DOM 节点,绝对不会出错。
for
The text was updated successfully, but these errors were encountered:
No branches or pull requests
正文
用
document.querySelectorAll
获取到一批 DOM 节点之后,常常需要遍历这些节点,为每个节点绑定对应的事件。在 JavaScript closure inside loops – simple practical example 中虽然讲到可以用
forEach
、let
,但是在部门的 iPhone 4、三星平板这两部旧设备上,无法使用这些新特性。上网查了一下,在 Using forEach on an array from getElementsByClassName results in “TypeError: undefined is not a function” 中讲到,用
document.querySelectorAll
之类的方法获取到的 DOM 节点,是 HTMLCollection,是“类数组对象”,所以在一些旧设备上,是无法使用forEach
这样的方法来遍历 DOM 节点的。最保险的方法,就是采用最原始的
for
循环来遍历这些 DOM 节点,绝对不会出错。参考资料
The text was updated successfully, but these errors were encountered: