我一直在尝试创建由JavaScript创建的表。我终于找到了一种创建表的方法,但是我缺乏将输入标签和表格放入该表的知识
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "Replace this with other input";
cell2.innerHTML = "Replace this with input";
样式无关紧要,我拥有所有需要的代码
答案 0 :(得分:1)
解决方案:
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var input1=document.createElement('input');
input1.setAttribute('type','text');
input1.value='input1';
var input2=document.createElement('input');
input2.setAttribute('type','text');
input2.value='input2';
cell1.appendChild(input1)
cell2.appendChild(input2)
<table id="myTable"></table>