HTML表固定顶行没有

问题描述 投票:0回答:1

我使用PHPExcel库将Excel文件转换为html表。

编辑输出:https://jsfiddle.net/simsimzzz/d1ccqveq/15/

我怎么能(JQuery?)将顶行固定为<thead>

    <table border="0" cellpadding="0" cellspacing="0" id="sheet0" class="sheet0 gridlines">
        <colgroup>
        <col class="col0">
        <col class="col1">
        <col class="col2">
        <col class="col3">
        </colgroup>
<tbody>
          <tr class="row0">
            <td class="column0 style3 s">Client Type</td>
            <td class="column1 style3 s">Client</td>
            <td class="column2 style3 s">N° Incident</td>
            <td class="column3 style3 s">blabla</td>
</tr>
</tbody>

PHPExcel不生成<thead></thead> ..

编辑:现在我有一个<thead></thead>,我怎么能修复这个并保持细胞的宽度根据<tbody>

jquery html-table phpexcel
1个回答
2
投票

似乎你需要创建一个<thead>然后从<tbody>移动标题行。

试试这个 :

jQuery(function($) {
    var $table = $('#sheet0'); // select the table of interest
    var $thead = $('<thead/>').prependTo($table); // create <thead></thead>
    $table.find('tbody tr').eq(0).appendTo($thead); // move the header row from tbody into thead

    // Now the table is ready to have your chosen method applied to fix the position of the thead.

});
© www.soinside.com 2019 - 2024. All rights reserved.