日期:2014-05-16  浏览次数:20424 次

如何将table的前几行几列锁定,其他部分自由滚动?
如题,另外最好可以控制一下锁定行列的外观以示区别

------解决方案--------------------
原来在 IE 6 下面试验过可以,

不过刚才 IE 7 下发现效果不对了,IE 7 越修麻烦越多了!

楼主如果用 IE 6 看看效果对不?俺用 IE 7,效果一塌糊涂了,哈

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> lock column </title>
<meta name= "generator " content= "editplus " />
<meta name= "author " content= "yixianggao@126.com " />
<meta name= "keywords " content= "javascript " />
<meta name= "description " content= "for javascript region of csdn " />
<style type= "text/css ">
table {
border: #a4cdf2 1px solid;
}
th {
border: #a4cdf2 1px solid;
font-family: "courier new ";
font-size: 11pt;
background-color: #ffff82;
position: relative;
top: expression(document.getElementById( "divTableContainer ").scrollTop);
z-index: 10;
}
td.locked {
position: relative;
left: expression(document.getElementById( "divTableContainer ").scrollLeft + "px ");
background-color: #ffff82;
}
td {
border: #a4cdf2 1px solid;
font-family: "courier new ";
font-size: 11pt;
}

</style>
</head>

<body>
<div id= "divTableContainer " style= "width: 298px; overflow: auto; ">
<table cellpadding= "0 " cellspacing= "0 " id= "tabTarget ">
<tr>
<th nowrap class= "locked "> Column A </th>
<th nowrap> Column B </th>
<th nowrap> Column C </th>
<th nowrap> Column D </th>
<th nowrap> Column E </th>
</tr>
<tr>
<td class= "locked "> R1.1 </td>
<td> R1.2 </td>
<td> R1.3 </td>
<td> R1.4 </td>
<td> R1.5 </td>
</tr>
<tr>
<td class= "locked "> R2.1 </td>
<td> R2.2 </td>
<td> R2.3 </td>
<td> R2.4 </td>
<td> R2.5 </td>
</tr>
<tr>
<td class= "locked "> R3.1 </td>
<td> R3.2 </td>
<td> R3.3 </td>
<td> R3.4 </td>
<td> R3.5 </td>
</tr>
</table>
</div>
</body>

</html>