固定表格
经常使用,笔记用

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <style> .table{ margin-bottom:0; border:0; } .body-first{ overflow: hidden; } .body-second{ overflow: scroll; } .body-first,.body-second{ width: 570px; } .header-second,.body-second{ height: 500px; } .header-first,.header-second{ width: 250px; overflow: hidden; } .header-first th,.header-second td,.body-first th,.body-second td{ width: 100px; } .coupons-title li{ width:49%; } </style> <c:if test="${dataList!= null && fn:length(dataList) > 0}"> <table cellspacing="0" cellpadding="0" class="text-center mt20"> <tr> <td> <div class="header-first"> <table class="table text-center table-fixed data-table"> <thead> <tr> <th>左侧固定列 头部1</th> <th>左侧固定列 头部2</th> <th>左侧固定列 头部3</th> </tr> </thead> </table> </div> <div class="header-second"> <table class="table text-center table-fixed data-table"> <thead> <tr> <td>左侧固定列 内容1</td> <td>左侧固定列 内容2</td> <td>左侧固定列 内容3</td> </tr> </thead> </table> </div> </td> <td> <div class="body-first"> <table class="table text-center table-fixed data-table"> <thead id="bodyData"> <th>右侧列 头部1</th> <th>右侧列 头部2</th> <th>右侧列 头部3</th> </thead> </table> </div> <div class="body-second"> <table class="table text-center table-fixed data-table"> <tbody> <tr> <td>右侧列 内容1</td> <td>右侧列 内容2</td> <td>右侧列 内容3</td> </tr> </tbody> </table> </div> </td> </tr> </table> </c:if> <c:if test="${dataList== null || fn:length(dataList) == 0}"> <div class="notSearchContent">没有查到数据,试试其他查询条件吧!</div> </c:if> <script> //设置表格 function setTable(){ //初始化宽度和高度; var bodyFirstWidth=$('.body-first table').width(); var headerSecondHeight=$('.header-second table').height(); $('.body-second table').width(bodyFirstWidth); $('.body-second table').height(headerSecondHeight); //设置滚动 $('.body-second').on('scroll',function(){ var left = $(this).scrollLeft(); var top = $(this).scrollTop(); $('.body-first table').css('margin-left',(-left)+'px'); $('.header-second table').css('margin-top',(-top)+'px'); }); }; setTable(); </script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!