childNodes遍历DOM节点树
var s = ""; function travel(space,node) { if(node.tagName){ s += space + node.tagName + "</br>" } var len = node.childNodes.length for (var i=0; i<len; i++){ travel(space+"--",node.childNodes[i]) } } travel("*", document) document.write(s);