我只是想在這里插入一個感嘆號 SVG,但我似乎做不到,而且我無法在 Google 上找到足夠的答案。
SVG 已下載,并包含在我的專案檔案夾中。
if(email.validity.valueMissing) {
emailError.textContent = '(SVG Here) You need to enter an e-mail address.';
uj5u.com熱心網友回復:
假設e-mailError是您的 html 中的顯示元素(span、p、div 等),可以通過設定.innerHTML元素的屬性來加載圖示和相關文本。
的使用.textContent將導致顯示標記文本而不是預期的布局(如您所見)
這個作業片段展示了差異。
const emailError=document.getElementsByClassName("emailError");
emailError[0].innerHTML = '<img src="https://stackoverflow.design/assets/img/logos/sf/sf-icon.svg" /> You need to enter an e-mail address.';
emailError[1].textContent = '<img src="https://stackoverflow.design/assets/img/logos/sf/sf-icon.svg" /> You need to enter an e-mail address.';
img {
width: 40px;
aspect-ratio: 1;
}
span {
border: 1px solid black;
display: flex;
align-items: center;
}
<p>Example loaded using .innerHTML:</p>
<p><span class="emailError"></span></p>
<p>Example loaded using .textContent:</p>
<p><span class="emailError"></span></p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/461985.html
標籤:javascript html css 网络 网络部署
上一篇:列印時溢位隱藏影像根本不顯示
