我无法并排创建两个表(模拟交易或没有交易金钱表)。我知道我可以创建一个包含两列的表,但是我想拥有一个高表和一个低表,以便将来轻松管理。这是我的代码:
amounts = [0.01, 1, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000, 1000000]
var tableString = "<table border=1>";
for (i = 0; i < 24; i ++){
tableString += "<tr><td>";
tableString += amounts[i];
tableString += "</td></tr>";
if (i == 11){
var Table = $(document.createElement('span')).attr("id", "low");
Table.html(tableString + '</table>');
Table.appendTo(".amounts");
tableString = "<table border=1>";
}
if (i == 23){
var Table = $(document.createElement('span')).attr("id", "high");
Table.html(tableString + '</table>');
Table.appendTo(".amounts");
}
}
我的HTML:
<div class='amounts'>
</div>
但我没有并排获得两张桌子(即使我创建了span元素)。它看起来就像我使用div元素。有人能帮助我吗?
答案 0 :(得分:0)
这可能是另一种方式:
var amounts = [0.01, 1, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000, 1000000] ;
function createTable(el, split){
var tableString = "<table border=1>";
for (var i = 0; i < el.length/2; i++){
if(i%split == 0){ tableString += "<tr>"; }
tableString += '<td>'+el[i]+'</td><td>'+el[i+el.length/2]+'</td>';
if(i%split == 0){ tableString += "</tr>"; }
}
tableString += '</table>';
var table = $(tableString);
table.appendTo(".amounts");
}
createTable(amounts, 2);