节点列表和HTML集合

getElementsByName()和getElementByTagName()返回的都是NodeList集合。

而document.images和document0.forms的属性为HTMLCollection对象。

这些对象都是只读的类数组对象昂,他们都有length属性,可以使用如下标准的循环进行迭代:

for(var i=0;i<document.images.length;i++)

    document.images[i].style.display = "none";

不能直接在NodeList和HTML集合上使用Array的方法,但可以间接地使用:

var snapshot = Array.prototype.slice.call(nodelist,0);

原文地址:https://www.cnblogs.com/mingluosunshan/p/3286465.html