table表格头部和前⼏列固定js
表格内容很多,需要把成表格的第1⾏和前4列固定住,其他td滑动。
我看了js⽂件,在获取td和th的宽⾼时有些⽤的innerWidth()和height();innerWidth()包括padding,但是不包括border和margin;height()不包含padding,border和margin;我猜是因为这个⽽造成错位的;
实现原理就是把头部和前⼏列复制出来单独另两个表格,然后⽤定位;代码有点多直接复制粘贴就可以了,如需改左边固定列数,改leftIndex的值就ok了;
$(function() {
//表格固定头部
if ($("#J_MagicTable").length > 0) {
var blockHeadingHeight = $("#J_BlockHeading").outerHeight();
$('#J_MagicTable').magicTable({thfix: blockHeadingHeight, leftIndex: 3, leftFlg: true});//leftIndex:3;左边固定四列
}
});
独⽴代码:html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>表格第⼀⾏和前⼏列固定</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="libs.baidu/bootstrap/3.0.3/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="./css/theme.css">
<script src="cdn.bootcss/jquery/1.11.1-rc1/jquery.js" type="text/javascript"></script>
<script src="libs.baidu/bootstrap/3.0.3/js/bootstrap.js"></script>
<script src="./js/magicTable.js" type="text/javascript"></script>
</head>
<body>
<div class="row-fluid row-data">
<table id="J_MagicTableTop" class="table table-striped table-bordered table-hover" ></table>
<table id="J_MagicTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th >⽇期</th>
<th >QQQ</th>
<th >第三</th>
<th ><a href="#">第四</a></th>
<th title="当⽇点击⽤户(去重)/当⽇活跃⽤户">第五</th>
<th title="点击总数/当⽇活跃⽤户">第六</th>
<th >第七</th>
<th >第⼋</th>
<th >第九</th>
<th >第⼗</th>
<th >第⼗⼀</th>
<th >第⼗⼆</th>
<th >第⼗三</th>
<th >第⼗四</th>
<th >第⼗五</th>
<th >第⼗六</th>
<th >第⼗七</th>
<th >第⼗⼋</th>
<th >第⼗九</th>
<th >第⼆⼗</th>
<th >第⼆⼗⼀</th>
<th >第⼆⼗⼆</th>
</tr>
</thead>
<tbody>
<tr>
<td>2011-01-01</td>
<td>65757657</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>楷艰⽤</td>
<td>梦</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-12-31</td>
<td>8797898980</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >为什么会这样⼦呢电视剧啊肯定会及扩散⼤数据库⼤家撒⼤叔控登记卡萨记得啊数据库⼤叔控打卡上打卡上⼤家看阿斯达克杀菌灯刷卡⼤家撒打卡 <td >7898790%</td>
</tr>
<tr>
<td>2061-11-31</td>
<td>ddffgdgdfgfd</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2019-11-31</td>
<td>dxcghfhyuyt222</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-11-31</td>
<td>467867thgjhmmhm</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-11-31</td>
<td>467867thgjhmmhm</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-11-31</td>
<td>dxcghfhyuyt222</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >电话费等接⼝是否和⼤家可舒服的健⾝房和⼤家上飞机对双⽅都技术开发⽕炬⼤厦发动机上房顶上</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-11-31</td>
<td>65757657</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>为什么使用bootstrap?
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>楷艰⽤</td>
<td>梦</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2011-12-31</td>
<td>8797898980</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2061-11-31</td>
<td>ddffgdgdfgfd</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
<td>4353535%</td>
<td >567686%</td>
<td >789798%</td>
<td >456546456%</td>
<td >7898790%</td>
</tr>
<tr>
<td>2019-11-31</td>
<td>dxcghfhyuyt222</td>
<td>fdsffdg</td>
<td><a href="#" title="点击查看平均单次使⽤时长明细" data-toggle="modal" data-target="#J_LaunchDurationModal" data-backdrop="false" data-ke <td>111</td>
<td><a target="_blank" href="#">545645</a></td>
<td>555</td>
<td>333</td>
<td class="cRed"><a target="_blank" href="#">444%</a></td>
<td class="cRed"><a target="_blank" href="#">2343535%</a></td>
<td>24354456</td>
<td>7897565656654</td>
<td>23432432%</td>
<td >2342432234545</td>
<td >6787687686</td>
<td >232222</td>
<td >453546786</td>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论