JS表头冻结

来源:互联网 发布:淘宝网足球 编辑:程序博客网 时间:2024/04/27 20:33

http://www.toumai.cn/download.asp

JS 文件:

function writeTitleDiv(height,wid)
{
 document.write ("<div id='div_title' style='OVERFLOW-Y: hidden; Z-INDEX: 100; OVERFLOW-X: hidden; OVERFLOW: scroll; WIDTH:"+wid+"%; left: 10px; POSITION: absolute; HEIGHT:"+height+"px'>")
}

function writeBodyDiv(top,wid)
{

 var width = wid;
 var height = document.body.clientHeight - top;
 document.write ("<div id='div_table' style='position:absolute; width:"
 +width+"%; height:"+height+"px; z-index:1; right:30px; left: 10px; top:"
 +top+"px; overflow: scroll;'  onscroll='return buildTitle()'>");
}

function buildTitle()
{
 
 div_title.style.posTop =div_table.style.posTop - 1;
 
 div_title.scrollLeft = div_table.scrollLeft;
 var maxrowSpan;//td_maxrow.rowSpan
 maxrowSpan = maxRowTd.rowSpan;
 if(maxrowSpan == null)
 {
  maxrowSpan = 1;
 }
 for(var j=0;j<maxrowSpan;j++)
 {
  for(var i=0;i<table_table.rows(j).cells.length;i++)
  {
   if(table_title.rows(j).cells(i).offsetWidth < table_table.rows(j).cells(i).offsetWidth)
   {
    //alert(table_title.rows(j).cells(i).style.posWidth);
    if(table_table.rows(j).cells(i).style.width.length == 0)
    {
     table_title.rows(j).cells(i).style.posWidth = table_table.rows(j).cells(i).offsetWidth;
    }
    else
    {
     table_title.rows(j).cells(i).style.width = table_table.rows(j).cells(i).style.width;
    }
   }
   else
   { if(table_title.rows(j).cells(i).style.width.length == 0)
    {
     table_table.rows(j).cells(i).style.posWidth = table_title.rows(j).cells(i).offsetWidth ;
    }
    else
    {
     table_table.rows(j).cells(i).style.width = table_title.rows(j).cells(i).style.width;
    }
   
   }
  }
 }
 div_title.style.width = div_table.clientWidth;
}
function killErrors() {return true;}  
window.onerror = killErrors;


ASPX文件:

<%@ Page language="c#" Codebehind="FailsummaryDMP.aspx.cs" AutoEventWireup="false" Inherits="Report.Report.DMPL10.failsummaryDMP" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>failsummaryDMP</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
  <meta content=C# name=CODE_LANGUAGE>
  <meta content=JavaScript name=vs_defaultClientScript>
  <meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
  <LINK href="../../../../INC/CSS/style.css" type=text/css rel=stylesheet >
  <meta http-equiv=Content-Type content="text/html; charset=big5">
  <script language="javascript">
  <!--#i nclude file="../../../../INC/JS/Common.js"-->
  </script>
</HEAD>
<body language=javascript onresize="return buildTitle();" rightMargin="20" topMargin=5 scroll=no
onload="return buildTitle();">
<form id=Form1 method=post runat="server">
<TABLE id=Title runat="server">
  <TR>
    <TD noWrap><asp:placeholder id=placeReport_Title
       Runat="server"></asp:placeholder></TD></TR></TABLE>
<table>
  <tr width="100%">
    <td align=right width=100></TD></TR></TABLE></FORM>
  <script language="javascript">
   writeTitleDiv(50,100);
  </script>
  <asp:label id=Label_titlesub runat="server" EnableViewState="False"></asp:label>
  <script language="javascript">
   document.write("</div>");
  </script>
  <table>
   <tr>
    <td nowrap id="td1"><asp:label id="Label_Query_Info" runat="server" EnableViewState="False"></asp:label>
    </td>
   </tr>
  </table>
  <script language = "javascript">
   writeBodyDiv(130,100);
  </script>
  <asp:label id="lbl_DataTable" runat="server" EnableViewState="False"></asp:label>
  <TABLE>
   <TR>
    <TD>
     <asp:PlaceHolder id="placeMessage" Runat="server"></asp:PlaceHolder></TD>
   </TR>
  </TABLE>
  <script language="javascript">
   document.write ("</div>");buildTitle();buildTitle();
  </script>

 </body>
</HTML>
CS:

#region [ Query Info ]

   Label_Query_Info.Text = @"<table><tr class = 'tip'><td>  </td></tr></table>";

   #endregion

   #region [ Table Title ]

   string tablehead =@"
   <table id='table_table' class='haveborder' border='1' bordercolor = '#000000'>
   <tr class = 'head'>
    <td id = 'maxRowTd' nowrap>Item</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>S</td>
    <td nowrap>A</td>
    <td nowrap>E</td>
    <td nowrap>W</td>
   </tr>
";

   strTable.Append(tablehead);
   if(Request.QueryString["Excel"] == null)
   {
    Label_titlesub.Text = @"<table
id='table_title' class='haveborder' border='1' bordercolor = '#000000' runat='server'>
    <tr class = 'head' nowrap>
    <td nowrap>Item</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>A</td>
    <td nowrap>S</td>
    <td nowrap>A</td>
    <td nowrap>E</td>
    <td nowrap>W</td>
   </tr></table>";
   }
   #endregion

 
原创粉丝点击