Javascript 表格单元格中的每行一个按钮

Javascript 表格单元格中的每行一个按钮,javascript,Javascript,我试图用JavaScript将2个按钮放入一个表单元格中 我有这样的想法: var table_cell = document.getElementById("table_cell") var button_A = document.createElement("input") button_A.setAttribute("value","BUTTON A") button_A.setAttribute("type","button") var button_B = document.creat

我试图用JavaScript将2个按钮放入一个表单元格中

我有这样的想法:

var table_cell = document.getElementById("table_cell")
var button_A = document.createElement("input")
button_A.setAttribute("value","BUTTON A")
button_A.setAttribute("type","button")
var button_B = document.createElement("input")
button_B.setAttribute("value","BUTTON A")
button_B.setAttribute("type","button")
table_cell.appendChild(button_A)
table_cell.appendChild(button_B)
按钮并排排列,而不是一个向上一个向下。 我正试图使它,使有一个按钮,每一个级别

 _____________   
|  _________  |   
| |_________| |     
|  _________  |   
| |_________| |     
|_____________|  
而不是

 __________________________
|  _________   _________   |
| |_________| |_________|  |
|__________________________|
我尝试在包含转义字符(如“\r\n”和“ &38”)的table_单元格中附加一个textnode,但都不起作用


如果有JS解决方案,我将不胜感激。在按钮之间使用

标记如何

table_cell.appendChild(button_A)
table_cell.appendChild(document.createElement("br"))
table_cell.appendChild(button_B)
table_cell.appendChild(button_A);
table_cell.appendChild(document.createElement('br'));
table_cell.appendChild(button_B);
你可以做:

button_A.style.display = 'block';
button_B.style.display = 'block';
但使用CSS可能是最好的:

input[type="button"] {
    display:block;
}
添加换行符(

)元素:

var table_cell=document.getElementById(“table_cell”);
var button_A=document.createElement(“输入”);
按钮A.setAttribute(“值”、“按钮A”);
按钮设置属性(“类型”、“按钮”);
var button_B=document.createElement(“输入”);
按钮设置属性(“值”、“按钮A”);
按钮设置属性(“类型”、“按钮”);

var newline=document.createElement(“br”);//在按钮之间添加一个空格(

)?CSS不是一个选项吗?嗯,我想知道如何使用CSS存档?@user1486030为按钮添加适当的选择器,我认为
显示:block
可以正常工作。标记没有帮助;)是的,确认过了。document.createElement('br')有效!谢谢你,穆萨!太糟糕了,所以不允许编辑少于6个字符,即使这非常合理@穆萨:我指的是你第一句话中的拼写错误,而不是
。@Musa SebastianG所说的拼写:)如果CSS解决方案也能发布,那将不胜感激
var table_cell = document.getElementById("table_cell");
var button_A = document.createElement("input");
button_A.setAttribute("value","BUTTON A");
button_A.setAttribute("type","button");
var button_B = document.createElement("input");
button_B.setAttribute("value","BUTTON A");
button_B.setAttribute("type","button");
var newline = document.createElement("br"); // <-- Add a newline
table_cell.appendChild(button_A);
table_cell.appendChild(newline); // <-- and append
table_cell.appendChild(button_B);