你能告诉我如何在javascript中编写以下伪代码吗?
for each child of <body>:
if (tag.haschildren):
for each tag.child:
do some action;
谢谢
答案 0 :(得分:1)
var els = document.getElementsByTagName("*");
for (var i = 0, ii = els.length; i < ii; i++) {
for (var j = 0, jj = els[i].childNodes.length; j < jj; j++) {
action(els[i].childNodes[j]);
}
}