日期:2014-05-20  浏览次数:20763 次

关于JavaScript中的表格冻结问题~~多谢~~~
各位好,小弟刚接触jsp,遇到一个问题。我建立了一个表格,现在我想实现表头冻结(下拉时第一行不动),应该怎么添加JS代码?我看到过网上的例子,他们都是直接输入的数据,而我的数据是从数据库中提取的,应该怎么做呢?JS代码怎么写?
麻烦各位高人指点指点~~~


Java code

<table border="2" width="100%" >
    <tr  >
        <td height="25" width="100" align="center">年月</td>
        <td height="25" width="155" align="center">货物名</td>
        <td height="25" width="75" align="center">入库人</td>
        <td height="25" width="130" align="center">备注</td>
......


while(rs.next()){

%>
    <tr>
        <td align="center"  ><%=rs.getDate(1)%></td>
        <td width="144"   ><%=rs.getObject(2)%> </td>
        <td width="73" align="center" > <%=rs.getObject(3)%></td>
        <td width="82" align="center" > <%=rs.getObject(4)%></td>
......





小弟感谢各位了~~~我只有20分了,悉数奉上~~

------解决方案--------------------
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>MyHtml.html</title>
</head>

<style type="text/css">
.fixedtd{
    color:#FF0000;
    position:relative;
    top: expression(this.parentElement.parentElement.parentElement.scrollTop)
    z-index:1;
}
</style>
<body>
<div style="overflow:auto; height:100px; width: 690px;">
  <table width="667" cellpadding="0" cellspacing="0" border="1">
    <tr bgcolor="gray">
      <td class="fixedtd" width="86">11111</td>
      <td class="fixedtd" width="120">22222</td>
      <td class="fixedtd" width="439">33333</td>
    </tr>
    <tr>
      <td>aaaaaa</td>
      <td>aaaaaa</td>
      <td>aaaaaa</td>
    </tr>
    <tr>
      <td>bbbbbb</td>
      <td>bbbbbb</td>
      <td>bbbbbb</td>
    </tr>
    <tr>
      <td>cccccc</td>
      <td>cccccc</td>
      <td>cccccc</td>
    </tr>
    <tr>
      <td>dddddd</td>
      <td>dddddd</td>
      <td>dddddd</td>
    </tr>
    <tr>
      <td>eeeeee</td>
      <td>eeeeee</td>
      <td>eeeeee</td>
    </tr>
    <tr>
      <td>ffffff</td>
      <td>ffffff</td>
      <td>ffffff</td>
    </tr>
    <tr>
      <td>gggggg</td>
      <td>gggggg</td>
      <td>gggggg</td>
    </tr>
    <tr>
      <td>hhhhhh</td>
      <td>hhhhhh</td>
      <td>hhhhhh</td>
    </tr>
    <tr>
      <td>iiiiii</td>
      <td>iiiiii</td>
      <td>iiiiii</td>
    </tr>
  </table>
</div>
</body>
</html>