我有一個 td,我想添加一個新的,但我的新 td 在我的頁面上顯示為文本,我缺少什么代碼:
var firstTd = parent.document.getElementById("currentTd");
firstTd.after('<td><span>teste</span></td>');
uj5u.com熱心網友回復:
請參閱檔案:
Element.after() 方法在元素的父元素的子串列中插入一組節點或字串物件,就在元素之后。字串物件作為等效的文本節點插入。
所以改為傳遞一個元素。
const firstTd = parent.document.getElementById("currentTd");
const secondTd = document.createElement('td');
const span = document.createElement('span');
span.textContent = "teste";
secondTd.appendChild(span);
firstTd.after(secondTd);
或考慮insertAdjacentHTML
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/486799.html
標籤:html
下一篇:將行移到列CSS
