本文介绍了HTML表格固定的顶行没有< thead>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用PHPExcel库将Excel文件转换为html表。
EDITED 输出:
我如何(JQuery?)将第一行修复为< thead>
?
< table border =0cellpadding =0cellspacing =0id =sheet0class =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>客户类型< / td>
< td class =column1 style3 s>客户< / td>
< td class =column2 style3 s> N°Incident< / td>
< td class =column3 style3 s> blabla< / td>
< / tr>
< / tbody>
PHPExcel不生成< thead>< / thead>
..
编辑:现在我有< thead>< / thead> ;
,我该如何解决这个问题,并根据< tbody>
解决方案似乎你需要创建一个< thead>
然后将标题行移入其中< tbody>
。
试试这个:
jQuery(函数($){
var $ table = $('#sheet0'); //选择感兴趣的表
var $ thead = $( '< thead />')。prependTo($ table); //创建< thead>< / thead>
$ table.find('tbody tr')。eq(0).appendTo( $ thead); //将标题行从tbody移动到thead
//现在表已准备好应用您选择的方法来修复thead的位置。
});
I convert an Excel file into html table with the PHPExcel library.
EDITED output : https://jsfiddle.net/simsimzzz/d1ccqveq/15/
How can I ( JQuery ? ) fix the top row as a <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 doesn't generate <thead></thead>
..
EDIT : Now I have a <thead></thead>
, how can I fix this one and keep the width of cells according to the <tbody>
解决方案
Seems that you need create a <thead>
then move the header row into it, from of the <tbody>
.
Try this :
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.
});
这篇关于HTML表格固定的顶行没有< thead>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!