如何使用javascript向表中添加边框?

如何使用javascript向表中添加边框?,javascript,html,Javascript,Html,我想使用javascript将边框添加到我的表中,以便在使用 var table=document.createElement("table").style.border="1px solid"; 然后尝试像这样将行追加到此表 table.appendChild(newRow); 上面的行引发异常,如下所示: Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type '

我想使用javascript将边框添加到我的表中,以便在使用

var table=document.createElement("table").style.border="1px solid";
然后尝试像这样将行追加到此表

 table.appendChild(newRow);
上面的行引发异常,如下所示:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
如果我试图执行相同的代码,但没有给出边界,它就会正确执行 请帮我做这个

您正在将
“1px solid”
赋值给
边框
属性,并将求值结果(也是
“1px solid”
)赋值给

它是一个字符串,因此它没有
appendChild
方法是很自然的

如果以后要访问表本身,则需要将表本身存储在变量中

var table = document.createElement("table");
table.style.border = "1px solid";
table.appendChild(newRow);

请单击,然后单击代码段编辑器
[]
,并创建一个如果
console.log(table)
,您将看到它不是一个节点元素,而是一个字符串。你需要把你的线分成两行。多行的重复。例如,请执行