我想動態創建html表和表的數量將取決於我在數組中獲得的響應。新的表格應該在每6個元素之後創建,表格標題本身就是數組元素。 預期輸出是 -我們可以動態創建多個HTML表使用for循環jquery
-------------------------------------
| th1 | th2 | th3 | th4 | th5 | th6 |
-------------------------------------
| | | | | | |
-------------------------------------
代碼,用於產生表是如下,其中控制檯被正確打印,但元件沒有獲得創建並沒有得到任何錯誤太。
'<div id="findingDiv">';
for(var i=0;i<tables;i++){
console.log('i-',i);
'<table class="table table-bordered" style="margin-top: 10px; border:1px solid black; border-collapse : collapse;font-size: 30px;">'+
'<thead>'+
'<tr>';
for(var k=0;k<6;k++){
'<th id="header" style="color:black; font-size: 12px; border:1px solid black; text-align:center;border-color: rgb(166, 166, 166);"> historyTable[k] </th>';
console.log('k-',k);
}
'</table> \n';
}
有人能幫助我嗎?
我檢查了以前沒有用過的解決方案。 How to clone() a element n times? How to use loop in Jquery to add table multiple times into div Create a table dynamically using for loop in .html()
[如何使用jQuery動態添加表單元素](https://stackoverflow.com/questions/16744594/how-to-use-jquery-to-add-form-elements-dynamically) – Saksham