Javascript HTML表格元素无法使用其属性

Javascript HTML表格元素无法使用其属性,javascript,html,Javascript,Html,我正试图通过Javascript使内容成为DOM。 所以我创建了元素并附加到DOM中。 但是,属性未应用于表状边框。 我只能看到文字。 此外,我还试图在添加后更改attirube。但不起作用 @Jaeseo Lee您已经将“边框折叠:折叠”应用于您的表;由于此,您的边框将消失,您必须从代码中删除此样式。 我试过这个代码,效果很好 var iwContent = document.createElement("div"); iwContent.className = 'info

我正试图通过Javascript使内容成为DOM。 所以我创建了元素并附加到DOM中。 但是,属性未应用于表状边框。 我只能看到文字。 此外,我还试图在添加后更改attirube。但不起作用


@Jaeseo Lee您已经将“边框折叠:折叠”应用于您的表;由于此,您的边框将消失,您必须从代码中删除此样式。 我试过这个代码,效果很好

var iwContent = document.createElement("div");
iwContent.className = 'infowindow';
iwContent.setAttribute('style',"width:160px;text-align:center;padding:5px");

var h3 = document.createElement("h3");
var text = document.createTextNode("Hello");

h3.appendChild(text);
iwContent.appendChild(h3);

var table = document.createElement("table");
//table.border = '1';  //this is also working
table.width='50%';
table.height='50%';
table.style.textAlign = "center";
//table.setAttribute('border', '1');  //this is also working
table.setAttribute('style','border:1px solid blue; text-align:center;');


let thead = table.createTHead();
let row = thead.insertRow();
var th = document.createElement("th");

var text1 = document.createTextNode("name");
var text2 = document.createTextNode("manhole1");

th.appendChild(text1);
th.appendChild(text2);

row.appendChild(th);

iwContent.appendChild(row);
var iwContent = document.createElement("div");
iwContent.className = 'infowindow';
iwContent.setAttribute('style',"width:160px;text-align:center;padding:5px");

var h3 = document.createElement("h3");
var text = document.createTextNode("Hello");

h3.appendChild(text);
iwContent.appendChild(h3);

var table = document.createElement("table");
//table.border = '1';  //this is also working
table.width='50%';
table.height='50%';
table.style.textAlign = "center";
//table.setAttribute('border', '1');  //this is also working
table.setAttribute('style','border:1px solid blue; text-align:center;');


let thead = table.createTHead();
let row = thead.insertRow();
var th = document.createElement("th");

var text1 = document.createTextNode("name");
var text2 = document.createTextNode("manhole1");

th.appendChild(text1);
th.appendChild(text2);

row.appendChild(th);

iwContent.appendChild(row);