首页 > 其他 > 详细

Bootstrap固定表头

时间:2016-05-20 09:56:23      阅读:374      评论:0      收藏:0      [点我收藏+]

1.本文参照http://www.wenzhixin.net.cn/2014/08/10/fixed_table

<!DOCTYPE html>
<html lang="en">
<link href="static/css/bootstrap/bootstrap.css" rel="stylesheet" type="text/css">
<link href="static/css/bootstrap/bootstrap-table.css" rel="stylesheet" type="text/css">
<script src="static/js/jquery/jquery-2.1.4.js"></script>
<script src="static/js/bootstrap/bootstrap.js"></script>
<script src="static/js/bootstrap/bootstrap-table.js"></script>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="fixed-table-container" style="width:1000px;height: 400px;">
<div class="fixed-table-header">
<table style="margin-bottom:0" class="table table-striped table-bordered table-hover">
</table>
</div>
<div class="fixed-table-body">
<table class="table table-striped table-bordered table-hover " style="width:2000px;">
<thead>
<tr>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
<th>
<div class="th-inner">城市地区</div>
<div class="fht-cell"></div>
</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>2</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>3</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>4</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>5</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>6</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>7</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>8</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>9</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
<tr>
<td>10</td>
<td>中国中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
<td>中国</td>
</tr>
</table>
</div>
</div>
</body>
<script>
$(".fixed-table-header table").append($(".fixed-table-body thead").clone());
$(".fixed-table-body table thead").hide();
$(".fixed-table-header").width(980);
$(".fixed-table-header table").width($(".fixed-table-body table").width());
$(".fixed-table-body table tbody").find(‘tr:first-child‘).children().each(function (i) {

$(".fixed-table-header table").find(‘div.fht-cell‘).eq(i).width($(this).width());
});
$(".fixed-table-body").scroll(function () {
$(".fixed-table-body").scrollLeft();
$(".fixed-table-header").scrollLeft($(".fixed-table-body").scrollLeft());
});
</script>
</html>

效果图:

技术分享

 

Bootstrap固定表头

原文:http://www.cnblogs.com/zengt/p/5510948.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!