问题描述
我有一个基于 python 数据框的动态表,我在第 2 和第 23 列中添加了以下类:
$(".tablafiltros tbody tr td:nth-child(2)").addClass('ColNodo');
$(".tablafiltros tbody tr td:nth-child(23)").addClass('ColGest');
我还为 .ColGest 分配了以下属性:
$(".ColGest").attr("data-pk","index")
通过这种方式,我将相同的固定属性“data-pk”=“index”添加到“.ColGest”中的每个,但我需要的是为每个“.ColGest”分配一个属性,该属性是.ColNodo(单元格值)
提前致谢。
解决方法
// Loop over all .ColGest items
$('.ColGest').each(function(index) {
// get the ColNodo cell with same index as the current ColGest in the loop
const colNodoValue = $('.ColNodo')[index].text();
// add a data-value attribute with the colNodo value
$(this).attr("data-value",colNodoValue);
});