代码之家  ›  专栏  ›  技术社区  ›  Simon Delaunay

HTML表格固定顶行,无<thead>

  •  0
  • Simon Delaunay  · 技术社区  · 7 年前

    我使用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>

    1 回复  |  直到 7 年前
        1
  •  2
  •   Roamer-1888    7 年前

    看来你需要创建一个 <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.
    
    });