寻找一个css或jquery解决方案将这些动态加载的表分解为每行最多6个,创建表的脚本将它们全部内联,有时最多32个td.tables显示在一行中。我如何打破它们只有最多6个显示内联
这是HTML
<table class="scoreboardboxscore">
<tbody>
<tr data-bind="foreach: matchups">
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
</tr>
</tbody>
</table>
答案 0 :(得分:1)
您可以从表中获取所有td
,将它们放入新创建的tr
中,并在结尾删除原始tr
:
$(document).ready(function()
{
var elementsPerRow = 6;
var currentTr = $('<tr>');
var table = $('.scoreboardboxscore');
var tds = $('.scoreboardboxscore tr:first td');
tds.each(function(index)
{
currentTr.append(this);
if (index % elementsPerRow == elementsPerRow - 1)
{
table.append(currentTr);
currentTr = $('<tr>');
}
else if (index + 1 == tds.length)
{
table.append(currentTr);
}
});
$('.scoreboardboxscore tr:first').remove();
});