[英]Move first row of a HTML table under a thead tag using JavaScript
我有一個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>
標記中獲取表的第一行,在<tbody>
標記中獲取表的其余行:
<table id="myTableID">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</tbody>
</table>
我對JavaScript有基本的了解,但是不知道如何進行這種情況。 請任何幫助?
thead
元素 tr
插入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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.