<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!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>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
<!--
    function FixTable(TableID, FixColumnNumber, width, height) {
    /// <summary>
    ///     锁定表头和列
    ///     <para> sorex.cnblogs.com </para>
    /// </summary>
    /// <param name="TableID" type="String">
    ///     要锁定的Table的ID
    /// </param>
    /// <param name="FixColumnNumber" type="Number">
    ///     要锁定列的个数
    /// </param>
    /// <param name="width" type="Number">
    ///     显示的宽度
    /// </param>
    /// <param name="height" type="Number">
    ///     显示的高度
    /// </param>
    if ($("#" + TableID + "_tableLayout").length != 0) {
        $("#" + TableID + "_tableLayout").before($("#" + TableID));
        $("#" + TableID + "_tableLayout").empty();
    }
    else {
        $("#" + TableID).after("<div id='" + TableID + "_tableLayout' style='overflow:hidden;height:" + height + "px; width:" + width + "px;'></div>");
    }
    $('<div id="' + TableID + '_tableFix"></div>'
    + '<div id="' + TableID + '_tableHead"></div>'
    + '<div id="' + TableID + '_tableColumn"></div>'
    + '<div id="' + TableID + '_tableData"></div>').appendTo("#" + TableID + "_tableLayout");
    var oldtable = $("#" + TableID);
    var tableFixClone = oldtable.clone(true);
    tableFixClone.attr("id", TableID + "_tableFixClone");
    $("#" + TableID + "_tableFix").append(tableFixClone);
    var tableHeadClone = oldtable.clone(true);
    tableHeadClone.attr("id", TableID + "_tableHeadClone");
    $("#" + TableID + "_tableHead").append(tableHeadClone);
    var tableColumnClone = oldtable.clone(true);
    tableColumnClone.attr("id", TableID + "_tableColumnClone");
    $("#" + TableID + "_tableColumn").append(tableColumnClone);
    $("#" + TableID + "_tableData").append(oldtable);
    $("#" + TableID + "_tableLayout table").each(function () {
        $(this).css("margin", "0");
    });
    var HeadHeight = $("#" + TableID + "_tableHead thead").height();
    HeadHeight += 2;
    $("#" + TableID + "_tableHead").css("height", HeadHeight);
    $("#" + TableID + "_tableFix").css("height", HeadHeight);
    var ColumnsWidth = 0;
    var ColumnsNumber = 0;
    $("#" + TableID + "_tableColumn tr:last td:lt(" + FixColumnNumber + ")").each(function () {
        ColumnsWidth += $(this).outerWidth(true);
        ColumnsNumber++;
    });
    ColumnsWidth += 2;
    if ($.browser.msie) {
        switch ($.browser.version) {
            case "7.0":
                if (ColumnsNumber >= 3) ColumnsWidth--;
                break;
            case "8.0":
                if (ColumnsNumber >= 2) ColumnsWidth--;
                break;
        }
    }
    $("#" + TableID + "_tableColumn").css("width", ColumnsWidth);
    $("#" + TableID + "_tableFix").css("width", ColumnsWidth);
    $("#" + TableID + "_tableData").scroll(function () {
        $("#" + TableID + "_tableHead").scrollLeft($("#" + TableID + "_tableData").scrollLeft());
        $("#" + TableID + "_tableColumn").scrollTop($("#" + TableID + "_tableData").scrollTop());
    });
    $("#" + TableID + "_tableFix").css({ "overflow": "hidden", "position": "relative", "z-index": "50", "background-color": "Silver" });
    $("#" + TableID + "_tableHead").css({ "overflow": "hidden", "width": width - 17, "position": "relative", "z-index": "45", "background-color": "Silver" });
    $("#" + TableID + "_tableColumn").css({ "overflow": "hidden", "height": height - 17, "position": "relative", "z-index": "40", "background-color": "Silver" });
    $("#" + TableID + "_tableData").css({ "overflow": "scroll", "width": width, "height": height, "position": "relative", "z-index": "35" });
    if ($("#" + TableID + "_tableHead").width() > $("#" + TableID + "_tableFix table").width()) {
        $("#" + TableID + "_tableHead").css("width", $("#" + TableID + "_tableFix table").width());
        $("#" + TableID + "_tableData").css("width", $("#" + TableID + "_tableFix table").width() + 17);
    }
    if ($("#" + TableID + "_tableColumn").height() > $("#" + TableID + "_tableColumn table").height()) {
        $("#" + TableID + "_tableColumn").css("height", $("#" + TableID + "_tableColumn table").height());
        $("#" + TableID + "_tableData").css("height", $("#" + TableID + "_tableColumn table").height() + 17);
    }
    $("#" + TableID + "_tableFix").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableHead").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableColumn").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableData").offset($("#" + TableID + "_tableLayout").offset());
}
$(document).ready(function () {
            FixTable("MyTable", 2, 600, 300);
});
//-->
</script>
</head>
<body>
<table
    style="border-bottom-color: black; border-top-color: black; width: 1000px; color: #000000; border-right-color: black; font-size: medium; border-left-color: black"
    id="MyTable"
    border="1"
    cellspacing="0"
    cellpadding="0"
>
<thead>
    <tr>
        <th style="text-align: center; width: 80px" rowspan="3">
            姓名
        </th>
        <th style="text-align: center; width: 80px" rowspan="3">
            班级
        </th>
        <th style="text-align: center" colspan="10">
            成绩
        </th>
    </tr>
    <tr>
        <th style="text-align: center" colspan="3">
            主科
        </th>
        <th style="text-align: center" colspan="3">
            文科
        </th>
        <th style="text-align: center" colspan="3">
            理科
        </th>
        <th style="text-align: center; width: 80px" rowspan="2">
            总分
        </th>
        </tr>
    <tr>
        <th style="text-align: center; width: 80px">
            语文
        </th>
        <th style="text-align: center; width: 80px">
            数学
        </th>
        <th style="text-align: center; width: 80px">
            英语
        </th>
        <th style="text-align: center; width: 80px">
            政治
        </th>
        <th style="text-align: center; width: 80px">
            历史
        </th>
        <th style="text-align: center; width: 80px">
            地理
        </th>
        <th style="text-align: center; width: 80px">
            物理
        </th>
        <th style="text-align: center; width: 80px">
            化学
        </th>
        <th style="text-align: center; width: 80px">
            生物
        </th>
    </tr>
</thead>
    <tbody>
    <!-- 数据行 -->
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
                <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
        <tr>
            <td>
                学生32
            </td>
            <td>
                班级1
            </td>
            <td>
                29
            </td>
            <td>
                25
            </td>
            <td>
                146
            </td>
            <td>
                28
            </td>
            <td>
                79
            </td>
            <td>
                73
            </td>
            <td>
                47
            </td>
            <td>
                8
            </td>
            <td>
                91
            </td>
            <td>
                526
            </td>
        </tr>
    </tbody>
</table>
</body>
</html>

关于table 冻结 标头及列---js控制方法的更多相关文章

  1. js Table冻结表头示例代码

    Table冻结表头的js实现代码. Table冻结表头: <script type="text/javascript"> //冻结table的表头  function  ...

  2. 【jQuery 冻结任意行列】冻结任意行和列的jQuery插件

    实现原理: 创建多个div,div之间通过css实现层叠,每个div放置当前表格的克隆.例如:需要行冻结时,创建存放冻结行表格的div,通过设置z-index属性和position属性,让冻结行表格在 ...

  3. jQuery遍历Table表格的行和列

    遍历Table表格的行和列,在开发中比较常用的功能,特别是前端开发人员,不多说,直接上代码,下面代码只是弹出第一列字段,请各位自己根据需求修改和扩展! <!DOCTYPE html PUBLIC ...

  4. 合并table中某一列相邻的相同的行

    合并table中某一列相邻的相同的行​1. [代码]合并table中某一列相邻的相同的行  <!DOCTYPE html><html>    <head>      ...

  5. bootstrap table实现iview固定列的效果

    因为bootstrap自带的固定列效果满足不了公司需求,所以借助fixed-table这个插件完成了iview固定列的效果 <!DOCTYPE html> <html lang=&q ...

  6. paip.提升效率--数据绑定到table原理和流程Angular js jquery实现

    paip.提升效率--数据绑定到table原理和流程Angular js  jquery实现 html #--keyword 1 #---原理和流程 1 #----jq实现的代码 1 #-----An ...

  7. JavaScript实现获取table中某一列的值

    JavaScript实现获取table中某一列的值 1.实现源代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ ...

  8. paip.提高工作效率--数据绑定到table原则和过程Angular js jquery实现

    paip.提高工作效率--数据绑定到table原理和流程Angular js  jquery实现 html #--keyword 1 #---原理和流程 1 #----jq实现的代码 1 #----- ...

  9. CSS 控制table 滑动及调整列宽等问题总结

    一. 通过css控制table y方向上滚动 html中没有滚动条,可以根据overflow属性的scroll来对table显示不完全的内容进行滚动. 只是y方向上滚动,很简单,只要设置div的hei ...

随机推荐

  1. JavaEE开发之SpringMVC中的静态资源映射及服务器推送技术

    在上篇博客中,我们聊了<JavaEE开发之SpringMVC中的自定义拦截器及异常处理>.本篇博客我们继续的来聊SpringMVC的东西,下方我们将会聊到js.css这些静态文件的加载配置 ...

  2. python——面向对象相关

    其他相关 一.isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 1 2 3 4 5 6 class Foo(object):     pass   obj = Foo( ...

  3. HTTP长连接、短连接使用及测试

    概念 HTTP短连接(非持久连接)是指,客户端和服务端进行一次HTTP请求/响应之后,就关闭连接.所以,下一次的HTTP请求/响应操作就需要重新建立连接. HTTP长连接(持久连接)是指,客户端和服务 ...

  4. Oracle修改监听端口号1521[转]

    在oracle中,默认的监听端口号为1521,一旦有人扫描出这个端口号就会知道此服务器为oracle数据库服务器,存在极其大的安全隐患,在这里,教大家如何修改oracle默认端口号为9999: 1.查 ...

  5. 产品经理学Python:参数传递方式

    这是关于Python的第5篇文章,主要介绍下参数传递方式和如何设计自己的函数. (一) 本篇主要介绍2种参数传递方式. 位置参数 调用函数时,根据函数定义的参数位置来传递参数. def right_t ...

  6. codeforces 782B The Meeting Place Cannot Be Changed (三分)

    The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...

  7. WebGIS开源解决方案之矢量数据导入

    前几篇介绍了开源WebGIS开发环境的搭建,本篇开始陆续介绍这些软件的使用,WebGIS的开发,首要的问题是解决数据来源,本篇主要介绍矢量数据在开源空间数据库PostgreSQL中的存储.后续篇幅中再 ...

  8. Python基本语法--语句

    # -*- coding: utf-8 -*- #条件语句 ''' if 判断条件: 执行语句…… else: 执行语句…… ''' flag = False name = 'python' if n ...

  9. jquery之效果操作

    jQuery操作之效果 效果一共分五大类 一.基本 二.滑动 三.淡入淡出 四.自定义 五.设置 咱们先来看一下基本类 一.基本又分为 show() hide() toggle() html代码 &l ...

  10. css控制table的td宽度

    今天发现即使设置table的td.th宽度,仍是不管用,是根据table的td的内容来适应宽度,导致其他的th.td丢失. 下图就是浏览器渲染的table,导致缺失"端口"这一列, ...