解决方案,将表td分成6个或更少的行 [英] solution to break table td into rows of 6 or less

查看:86
本文介绍了解决方案,将表td分成6个或更少的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一个css或jquery解决方案来将这些动态加载的表分解为每行最多6个,创建表的脚本将它们全部内联,有时最多显示32个td.表在一行中显示.如何在最多只能显示6个内联的情况下打破它们

Looking for a css or jquery solution to break these dynamically loaded tables into a max of 6 per row , the script that creates the tables places them all inline , and sometimes up to 32 td.tables are shown in one row. How can i break them where only a max of 6 are to show inline

这是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>

推荐答案

您可以从表中获取所有td,将它们放入新创建的tr s中,并在最后删除原始的tr:

You can take all tds from table, put them into newly created trs and remove original tr at the end:

小提琴.

$(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();
});

这篇关于解决方案,将表td分成6个或更少的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆