Pushing arrays based on each row inputs dynamically

后端 未结 3 993
遇见更好的自我
遇见更好的自我 2021-01-27 05:32

Based on my code I want to push each row\'s inputs to each array. If it is row1, it should push all the input values of row 1 to array a1. The second row\'s inputs

3条回答
  •  独厮守ぢ
    2021-01-27 05:56

    I'd use $.map to create a nested array. It seems as if you want to have a lot of rows. So, I would recommend a 2d array instead of individual variables to avoid repetitive code. With a 2d array you can loop through each row; with individual variables you'd have to manually rewrite the same code for each row.

    $('#check').click(function(event){
      event.preventdefault;
      var serialize = [];
      $("#myTable tr").each(function () {
        serialize.push($.map($(this).find("input"), function (ele) {
          return ele.value;
        }));
      });
      console.log(serialize);
    });
    
    
    1
    1

提交回复
热议问题