[聚合文章] 运用jQuery冻结table表头

jQuery 2017-03-12 14 阅读

在网页中,如果表哥数据量在两个维度上都较大时是不便于查看数据的,如果能够像excel那样冻结表头将有助于提高数据查阅的体验和效率。目前可够选择的解决方案很多,如果不希望引入过多的第三方库,那么运用jQuery也可以实现简单的表格表头冻结。

  • 构建一个简单的表格
<!DOCTYPE html><html lang="zh-CN">    <head>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <meta name="viewport" content="width=device-width, initial-scale=1">        <title>简单表格</title>        <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->        <!--[if lt IE 9]>            <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>            <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>        <![endif]-->    </head>    <body>        <table class="table" id="main-table">            <thead>                <tr>                    <th>id</th>                    <th>name</th>                    <th>age</th>                    <th>sex</th>                    <th>posotion</th>                    <th>introduction</th>                </tr>            </thead>            <tbody>                <!-- 该行多次复制 -->                <tr>                    <td>1</td>                    <td>stone</td>                    <td>12</td>                    <td>male</td>                    <td>manager</td>                    <td>a man</td>                </tr>            </tbody>        </table>        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->        <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>        <!-- Include all compiled plugins (below), or include individual files as needed -->        <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>    </body></html>
                

注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版权等事宜,请你联系站长进行处理。