jquery - jquery设置表th的宽度等于td的宽度
问题描述
我在这里有一个 codepen - https://codepen.io/mt-ttmt/pen/OZRpdP
它是一个简单的表格,滚动时带有粘性标题
标头使用位置固定:固定;。这会从 th 中删除宽度
我想设置 th 的宽度,使它们与 td 的宽度相同
如何循环遍历 th 并将宽度设置为与 td 相同
$(function () {
$(window).scroll(function () {
var theadHeight = $(".js-table-thead").outerHeight();
var tablePos = $(".js-table").offset().top;
if ($(window).scrollTop() > tablePos) {
let stickyPos = ($(this).scrollTop() - tablePos);
$(".js-table-thead tr").addClass('fixed');
var th = $('.js-table-thead th');
var td = $('.js-table-tbody td');
th.each(function(index){
$(this).width() = td.width();
})
} else {
$(".js-table-thead tr").removeClass('fixed');
}
});
});
解决方案
推荐阅读
- java - 如何使用不包含的操作 url 制作 HTML GET 表单?
= 在里面? - javascript - 如何使用 js sale-count-to money 格式添加逗号分隔
- javascript - 为什么 jQuery formData 需要 contentType=false?
- ios - iOS 应用程序在设备上运行时失败 - “dyld: Library not loaded” “abort with payload”
- amazon-dynamodb - DynamoDB 更新 - “ValidationException:更新表达式中的操作数具有不正确的数据类型”
- angular - Angular 构建监视多个库并提供给另一个应用程序
- javascript - 如何检查文件中有多少个数组?
- c# - 在不破坏不变性的情况下更改属性值
- django - 502 Bad Gateway,我弄乱了用于 django 部署的 digitalocean ubuntu 上的用户和组权限
- c++ - C++ 错误:没有用于调用“toupper”的匹配函数