我的 HTML 有
cell = document.createElement("td");
cell.appendChild(document.createTextNode(contents));
cell.setAttribute('width', '100');
以下语法不起作用。
cell.appendChild(document.createElement('br')).appendChild(document.createTextNode("Another text"));
在单元格内容之后,我有一个换行符,后面是同一单元格中的另一个小写字母文本。我该怎么做?
最佳答案
首先,您要将一个文本节点附加到没有子级的 BR 标记。
尝试将线路分成两个调用:
cell.appendChild(document.createElement('br'));
cell.appendChild(document.createTextNode("Another text"));
关于JavaScript DOM 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/452837/