table表头固定

来源:互联网 发布:奇葩说范湉湉长相 知乎 编辑:程序博客网 时间:2024/06/10 19:41

直接上代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../ceshi01/js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
table {border-spacing: 0;border-collapse: collapse;}
.bj-table{height: 100px;overflow-y: auto;}
.bj-table table tr th { background-color: #d8d7d7; height: 30px;border: 1px solid #e1e1e1;text-align: center;padding: 0px 5px;}
.bj-table table tr td {height: 30px; border: 1px solid #e1e1e1;text-align: center;padding: 0px 8px;}
.g10{width: 100px;}
#notifyListTopTable,#bujian,#xiangjian{position: relative;}
#notifyListTopTable table thead{width:900px;position: absolute;z-index:999;}
#notifyListTopTable table tbody{ position: absolute;top:30px; width:900px;table-layout: fixed;}
#notifyListTopTable tbody tr td { table-layout: fixed;white-space: normal;line-height: 1.42857143;}
</style>
</head>
<body>
<div class="bj-table" id="notifyListTopTable">
<table style="width:900px;" id="notifyListTop">
<thead>
<tr>
<th class="g10">完结</th>
<th class="g10">单据编号</th>
<th class="g10">下单日期</th>
<th class="g10">开箱时间</th>
<th class="g10">开箱地点</th>
<th class="g10">参加单位</th>
<th class="g10">设备描述</th>
<th style="width:99px;">备注</th>
<th class="g10">制单人</th>
</tr>
</thead>
<tbody  id="notifyList">
<tr>
<td class="g10">是是是</td>
<td class="g10">是是是</td>
<td class="g10">  对对对</td>
<td class="g10">等等</td>
<td class="g10">   对对对</td>
<td class="g10">试试</td>
<td class="g10">嗯嗯</td>
<td style="width:99px;"> 是是是</td>
<td class="g10">啊啊啊</td>
</tr> 
</tbody> 
</table>
</div>
</body>
</html>
<script>       
$("#notifyListTopTable").scroll(function(){
var headerTopHeight  =  $("#notifyListTopTable")[0].scrollTop;
$("#notifyListTopTable thead").css("top",headerTopHeight+"px");
})
</script>

原创粉丝点击