1 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
您需要循環(huán)該getElementsByName()
函數(shù)的結(jié)果,因?yàn)樗祷匾粋€(gè)集合。請(qǐng)參閱下面的示例。正如評(píng)論中提到的,您不應(yīng)該在 span 元素上使用 name 。最好使用類(lèi)選擇器。相同的邏輯適用于getElementsByClassName()
orquerySelectorAll()
函數(shù),因?yàn)檫@些函數(shù)也返回集合。
var telNo = '01234 567 8900 (8.30am till 5.30pm - Mon to Fri excluding bank holidays)';
document.getElementsByName('telNo').forEach((el) => {
el.innerHTML = telNo;
});
<div class="row m-0 d-flex align-items-center p-5">
<div class="col-12 col-lg-6 pr-lg-0">
<h1>Oops, something went wrong</h1>
<span id="otherErrorTxt" style="display: block">
<p>This error has occurred whilst processing your request.</p>
<p>If the error continues, please contact us on:</p>
<p name="telNo" class="text-muted"></p> <!-- TEL NO. TO GO HERE -->
</span>
<span id="fourOfourTxt">
<p>The page you are looking for is not available. This may be because of one of the following reasons:</p>
<ul class="mb-3">
<li>The page may have been moved or removed</li>
<li>The page may have had its name changed</li>
<li>You may have typed the URL incorrectly</li>
</ul>
</span>
<a class="btn btn-primary col-12 col-lg-2 mt-3" href="/">Go back</a>
</div>
</div>
<div class="row footer">
<div class="col-lg-4">
© 2020 Packnet Limited - All rights reserved
</div>
<div class="col text-right">
<i class="fas fa-phone fa-lg fa-rotate-90 mr-2"></i>
<span name="telNo"></span>
<!-- TEL NO. TO ALSO GO HERE -->
</div>
</div>
- 1 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)