我按类名尝试div中的所有文本:
<div class="something...">
然后用某些东西替换文本。不,我不想使用jquery。
答案 0 :(得分:2)
应该是直截了当的
var elements = document.querySelectorAll('.something');
for ( var i=elements.length; i--; ) {
elements[i].textContent = "something else";
}
&#13;
<div class="something">Soft</div>
<br>
<div class="something">Kitty</div>
<br>
<div class="something">Warm</div>
<br>
<div class="something">Kitty</div>
<br>
<span class="something" style="color:green">Little ball of fur ...</span>
&#13;