"use strict"
function fillTable() {
let job = document.getElementById("items").value;
let timeStamp = document.getElementById("when").value;
let tr = document.createElement('tr');
let td1 = tr.appendChild(document.createElement('td'));
let td2 = tr.appendChild(document.createElement('td'));
td1.innerHTML = job;
td2.innerHTML = timeStamp;
document.getElementById('ListTable').appendChild('tr');
}
这是我得到的错误。“无法在‘Node’上执行'appendChild‘:参数%1不是’Node‘类型”
据我所知,这是当类型不匹配时得到的错误,比如我试图将字符串直接附加到父节点。有人能帮我吗,因为我没有看到类型不匹配,或者我遗漏了一些非常明显的东西。
发布于 2021-04-16 11:46:00
将表行追加到父节点表时,传递了字符串“”tr“”(document.getElementById('ListTable').appendChild('tr');),而不是节点对象tr。“”
发布于 2021-04-16 12:06:17
"use strict"
function fillTable() {
let job = document.getElementById("items").value;
let timeStamp = document.getElementById("when").value;
let tr = document.createElement('tr');
let td1 = tr.appendChild(document.createElement('td'));
let td2 = tr.appendChild(document.createElement('td'));
td1.innerHTML = job;
td2.innerHTML = timeStamp;
document.getElementById('ListTable').appendChild(tr);
}https://stackoverflow.com/questions/67063142
复制相似问题