Simultaneously Iterating Over Two Sets of Elements in jQuery

前端 未结 2 1676
醉话见心
醉话见心 2021-01-22 08:17

I have a table containing many pairs of text input fields in separate columns. I want to iterate through the input fields in the first column and use those values to set the va

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 08:49

    Lots of ways to do this. Here's one.

    $("tr").each(function() {
      $(this).find(":last-child input").val($(this).find(":first-child input").val());
    });
    

    or another:

    $("input.left").each(function() {
      $(this).parent().nextSibling().find("input.right").val(this.value);
    });
    

    and so on.

提交回复
热议问题