【问题标题】:jquery add each <td> an attribute based on another <td> value in the same rowjquery 根据同一行中的另一个 <td> 值为每个 <td> 添加一个属性
【发布时间】:2021-05-04 10:04:44
【问题描述】:

我有一个基于 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(单元格值)

提前致谢。

【问题讨论】:

  • 嗨,这个问题解决了吗?

标签: jquery html-table cell attr


【解决方案1】:
// 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);

});

【讨论】:

    猜你喜欢
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2017-12-19
    相关资源
    最近更新 更多