本文介绍了对于 body 中的每个元素类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
For each div in body
div.innerHtml = "poo"
next div
这显然是伪代码,但展示了我想要做什么.
this is obviously psuedo code but demonstrates what i am trying to do.
编辑分享一下,看到 9 岁的问题让我非常高兴,看到我走了多远,这个问题仍然有益于他人.
Edit to share that it gives me tremendous joy to look at questions 9-years old and to see how far I've come and that this question still benefits others.
推荐答案
var elements = document.getElementsByTagName('div');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = "foo";
}
如果你只想查看:
var elements = document.body.getElementsByTagName('div');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = "foo";
}
这篇关于对于 body 中的每个元素类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!