简体   繁体   English

每次迭代时如何更新特定行的单元格的值

[英]How to update value of cell of specific row when iterating with each

I am getting the values of the first column of a table and based on an if statement I need to update the value of the third column of each specific row. 我正在获取表的第一列的值,并且基于if语句,我需要更新每个特定行的第三列的值。 This is what I do: 这是我的工作:

$("#attributes_tbl tr").each(function(){
  var value = $(this).find("td input:nth-child(2)").val();
  if (value in attribute_enumerations){
    description = attribute_enumerations[value]
    console.log(description)
    $('td:nth-child(3) input').val(description);
  }
});

The above snippet updates all the rows of the third column. 上面的代码片段更新了第三列的所有行。 What I need is to update the cell of the third column of the current row: 我需要更新当前行第三列的单元格:

// I need this to update only the specific cell of the current row (from the "each" loop)

$('td:nth-child(3) input').val(description); $('td:nth-​​child(3)input')。val(description);

How can I specify this in jQuery? 如何在jQuery中指定呢?

To affect only the current row, change: 要仅影响当前行,请更改:

$('td:nth-child(3) input').val(description);

To: 至:

$(this).find('td:nth-child(3) input').val(description);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM