HTML table 固定顶行没有 <thead>
HTML table fixed top row without <thead>
我使用 PHPExcel 库将 Excel 文件转换为 html table。
已编辑 输出: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>
..
EDIT :现在我有一个 <thead></thead>
,我该如何修复它并根据 <tbody>
[=19 保持单元格的宽度=]
似乎您需要创建一个 <thead>
,然后将 header 行移入其中,从 <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.
});
我使用 PHPExcel 库将 Excel 文件转换为 html table。
已编辑 输出: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>
..
EDIT :现在我有一个 <thead></thead>
,我该如何修复它并根据 <tbody>
[=19 保持单元格的宽度=]
似乎您需要创建一个 <thead>
,然后将 header 行移入其中,从 <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.
});