使用JavaScript在thead标记下移动HTML表的第一行

时间:2015-10-01 14:00:54

标签: javascript jquery html birt

我有一个由BIRT生成的html表如下:

<table id="myTableID">
    <tr>
        <th></th>
        <th></th>
        <th></th>
    </tr>

    <tr>
        <th></th>
        <th></th>
        <th></th>
    </tr>

    <tr>
        <th></th>
        <th></th>
        <th></th>
    </tr>
</table>

我想编写一个读取此表的JavaScript代码,并以下面的形式重写它:在<thead>标记中获取表的第一行,以及{{}中表的其余部分1}}标签:

<tbody>

我对JavaScript有基本的了解,但我不知道如何处理这种情况。请帮忙吗?

1 个答案:

答案 0 :(得分:5)

  1. 使用prependTo()插入thead元素
  2. 使用append()tr
  3. 中插入第一个thead

    $('<thead></thead>').prependTo('#myTableID').append($('#myTableID tr:first'));
    
    console.log($('#myTableID')[0].outerHTML);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <table id="myTableID">
        <tr>
            <th></th>
            <th></th>
            <th></th>
        </tr>
    
        <tr>
            <th></th>
            <th></th>
            <th></th>
        </tr>
    
        <tr>
            <th></th>
            <th></th>
            <th></th>
        </tr>
    </table>