簡體   English   中英

每次迭代時如何更新特定行的單元格的值

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

我正在獲取表的第一列的值,並且基於if語句,我需要更新每個特定行的第三列的值。 這是我的工作:

$("#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);
  }
});

上面的代碼片段更新了第三列的所有行。 我需要更新當前行第三列的單元格:

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

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

如何在jQuery中指定呢?

要僅影響當前行,請更改:

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

至:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM