2017-07-05 21 views
-4

我有一個數組,其中包含用戶在輸入表單中輸入的名稱,ID等的員工詳細信息。我想單獨使用div來以表格的形式打印這些細節。請告訴我的HTML部分和JavaScript的一部分。 我想在javascript中創建元素並打印輸入。該表包含5列和行被添加作爲用戶輸入他的輸入使用div標籤和DOM操作以表格的形式插入值(javascript)

+0

分享相關的代碼行添加到表。 –

+1

到目前爲止,您是否嘗試編寫至少1行代碼? –

+0

這裏的問題只是我的應用程序的一部分,不能在這裏發佈我的整個代碼! – Prag

回答

0

使用下面的代碼使用JavaScript

// Find a <table> element with id="myTable": 
var table = document.getElementById("myTable"); 

// Create an empty <tr> element and add it to the 1st position of the table: 
var row = table.insertRow(0); 

// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element: 
var cell1 = row.insertCell(0); 
var cell2 = row.insertCell(1); 

// Add some text to the new cells: 
cell1.innerHTML = "NEW CELL1"; 
cell2.innerHTML = "NEW CELL2"; 
+0

謝謝,但我的概率是,我有一個包裝div在我的HTML和我想在我的JavaScript創建元素,添加文本ti這些元素,並顯示它在包裝div。你能幫我解決嗎? – Prag

+0

當然!請分享您的現有代碼。 –