当前位置: 代码迷 >> 综合 >> js 固定表头及固定列的js
  详细解决方案

js 固定表头及固定列的js

热度:64   发布时间:2024-01-24 11:53:23.0

//给table 外层加一个div然后将divid传入方法,arr是一个数组里面填写需要固定的列数
function fixedCol(arr,divId){var colArr = arr || [];colArr.forEach(function(val){$("#"+divId).scroll(function(){var left = $("#"+divId).scrollLeft(); // 获取盒子滚动距离var trs = $("#"+divId+" table tr");   // 获取表格所有的tr// 获取每一行下面的td或者th,设置相对定位,偏移距离为盒子滚动的距离即 lefttrs.each(function(i){                 $(this).children().eq(val).css({"position":"relative","top":"0px","left":left,"background":"white"}); });});});                      
}#spmx{position: relative;background: #fff;z-index: 4;
}
#reyDiv{z-index: 3;
}
$(document).ready(function(){fixedCol([0,1,2],"spmx");});

 

  相关解决方案