jQuery根据<td> <td> 同一行中的另一个值添加每个属性



我有一个基于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"分配给每个人,但是我需要分配给每个人。作为.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);
});

最新更新