From comments: > That s because the "second match" immediately became the "first match" once the original first match was changed to no longer match. However, once you are done with the first iteration, your iterator will have already moved on to the second item, which would be what originally was the third, causing the originally-second to fall through the cracksWhy exactly iterator skips a value like that? Is it a simple for loop underneath?
I m 试图替换像<span id=“Something”/>
等我的超文本中的一些地方持有人。 我很想知道,为什么要用以下的 Java本代典代号取代第一起事件:
function set_placeholder(cls, txt)
{
txt = document.createTextNode(txt);
for (var e of document.getElementsByClassName(cls)) {
e.parentNode.replaceChild(txt, e);
}
}
在更换了<代码>span后,似乎无法找到下一个配对处。
因此,我试图
function set_placeholder(cls, txt)
{
for (var e of document.getElementsByClassName(cls)) {
e.innerText = txt;
}
}
现在,所有事件都会被取代,因此我想知道,这是我的过错,还是第一个变量失败时的浏览器(Firefox 102)。
HTML Sample
实际的超文本处理更为复杂,但这里有一些样本:
<html>
<p><span class="ph-customer" /> bestellte am <span class="ph-customer-date" /> folgende Artikel:</p>
<!-- ... -->
<table>
<tr>
<td><span class="ph-customer-date" />,
<span class="ph-customer-name" /></td>
</tr>
</table>
<!-- ... -->
</html>
例如ph-customer-date
电话:set_place holder (ph-customer-date , 30.12.2023 )
只能取代第一种情况。