简体   繁体   中英

Putting input into JavaScript Tables

I've been trying to create a table created by JavaScript. I finally found a way to create the table, but I lack the knowledge to put an input tag and a form into this table

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";

The style is irrelevant, I have all the code I need behind that

The Solution:

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM