---
title: "锁表头"
author: "lishoubin_123"
date: "2011-09-14T14:40:00Z"
tags: ["JavaScript"]
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2012-10-25T08:39:35Z"
id: 1704161
url: "https://lishoubin.iteye.com/blog/1704161"
---

&lt;div class="lockContainer" style="width: 99%;height:80%;overflow-x:hidden;"&gt;  
&lt;table class="formTable" width="100%" &gt;  
&lt;thead&gt;  
&lt;tr&gt;  
&lt;td class="Locked" style="width:100px;TEXT-ALIGN: center;"&gt;  
销售凭证  
&lt;/td&gt;  
&lt;td class="Locked" style="width:150px;TEXT-ALIGN: center;"&gt;  
车工号  
&lt;/td&gt;  
&lt;td class="Locked" style="width:100px;TEXT-ALIGN: center;"&gt;  
实际结束:执行(日期)  
&lt;/td&gt;  
&lt;td class="Locked" style="width:80px;TEXT-ALIGN: center;"&gt;  
订单优先级  
&lt;/td&gt;

&lt;/tr&gt;  
&lt;/thead&gt;  
&lt;tbody&gt;循环内容.............  
&lt;/tbody&gt;

&lt;/div&gt;

lockTable.css 内容如下

 

 

.lockContainer{  
overflow: scroll;border: solid 1px #86B9E4;  
}  
.lockTable{  
border-collapse: collapse;  
}  
.lockTable td  
{

position: relative;  
padding: 0.5px;  
border-top: solid 0px #86B9E4;  
border-bottom: solid 1px #86B9E4;  
border-left: solid 0px #86B9E4;  
border-right: solid 1px #86B9E4;  
}

.lockTable td.Locked /* 水平与垂直方向锁住单元格, 不随鼠标或滚动条移动 \*/  
{

z-index: 30; position: relative;  
background-color: #f3f3f3;  
text-align: center;  
border-top: solid 0px #86B9E4;  
border-bottom: solid 1px #86B9E4;  
border-left: solid 0px #86B9E4;  
border-right: solid 1px #86B9E4;  
top: expression(parentNode.parentNode.parentNode.parentNode.scrollTop);  
left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);

}

.lockTable td.HLocked /* 水平方向锁住单元格 \*/  
{

z-index: 10; position: relative;  
background-color: #f3f3f3;  
text-align: center;  
border-top: solid 0px #86B9E4;  
border-bottom: solid 1px #86B9E4;  
border-left: solid 0px #86B9E4;  
border-right: solid 1px #86B9E4;  
left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);

}

.lockTable td.VLocked /* 垂直方向锁住单元格 \*/  
{  
z-index: 20; position: relative;  
background-color: #f3f3f3;  
text-align: center;  
border-top: solid 0px #86B9E4;  
border-bottom: solid 1px #86B9E4;  
border-left: solid 0px #86B9E4;  
border-right: solid 1px #86B9E4;  
top: expression(parentNode.parentNode.parentNode.parentNode.scrollTop);  
}

.topbar  
{  
z-index: 30; position: relative;  
text-align: center;  
top: expression(parentNode.parentNode.parentNode.parentNode.scrollTop);  
left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);  
}