这是关于如何循环文档或元素的另一个示例:function getNodeList(elem){var l=new Array(elem),c=1,ret=new Array();//This first loop will loop until the count var is stable//for(var r=0;r<c;r++){ //This loop will loop thru the child element list// for(var z=0;z<l[r].childNodes.length;z++){ //Push the element to the return array. ret.push(l[r].childNodes[z]); if(l[r].childNodes[z].childNodes[0]){ l.push(l[r].childNodes[z]);c++; }//IF }//FOR}//FORreturn ret;}