如何< /tr>< tr>< /td>在Jquery或JavaScript的帮助下在每10之后添加append &lt;

rnmwe5a2  于 2023-10-17  发布在  jQuery
关注(0)|答案(1)|浏览(95)

我通过php file_put_contents生成了一个无限的表,在我的表中,我想在Jquery或JavaScript的帮助下在每个**10 </td>之后添加</tr><tr>**
下面是表的示例

<TABLE BORDER="1" WIDTH="100%" CLASS="Numbers">
<TR>
    <TD>img1</TD>
    <TD>img2</TD>
    <TD>img3</TD>
    <TD>img4</TD>
    <TD>img5</TD>
    <TD>img6</TD>
    <TD>img7</TD>
    <TD>img8</TD>
    <TD>img9</TD>
    <TD>img10</TD>
                           <==== i want here </TR><TR> , which will automatically add after EVERY 10 </td>
    <TD>img11</TD>
    <TD>img12</TD>
    <TD>img13</TD>
    <TD>img14</TD>
    <TD>img15</TD>
    <TD>img16</TD>
    <TD>img17</TD>
    <TD>img18</TD>
    <TD>img19</TD>
    <TD>img20</TD>
                                <=== i want it auto add </TR><TR> here after every 10 </TD>
    <TD>img21</TD>
    <TD>img22</TD>
    <TD>img23</TD>
    <TD>img24</TD>
    <TD>img25</TD>
    <TD>img26</TD>

表.继续

9gm1akwq

9gm1akwq1#

只需为前10个TD之后的每10个TD创建TR并将其附加到表中(实际上它将附加到tbody,但没关系,此代码确保它是正确的),然后将这些TD移动到新创建的行中

const cells = [...document.querySelectorAll('TD')].slice(10);
const target = cells[0].parentNode.parentNode;
while (cells.length) {
  target.appendChild(document.createElement('TR')).append(...cells.splice(0, 10));
}
<TABLE BORDER="1" WIDTH="100%" CLASS="Numbers">
<TR>
    <TD>img1</TD>
    <TD>img2</TD>
    <TD>img3</TD>
    <TD>img4</TD>
    <TD>img5</TD>
    <TD>img6</TD>
    <TD>img7</TD>
    <TD>img8</TD>
    <TD>img9</TD>
    <TD>img10</TD>
    <TD>img11</TD>
    <TD>img12</TD>
    <TD>img13</TD>
    <TD>img14</TD>
    <TD>img5</TD>
    <TD>img16</TD>
    <TD>img17</TD>
    <TD>img18</TD>
    <TD>img19</TD>
    <TD>img20</TD>
    <TD>img21</TD>
    <TD>img22</TD>
    <TD>img23</TD>
    <TD>img24</TD>
    <TD>img25</TD>
    <TD>img26</TD>
</TR>
</TABLE>

相关问题