1

Есть таблица, значения вводит пользователь, нужно значения из таблицы перевести в массив в виде матрицы

пока 2 проблемы:

1) создается 2 массива

2) не получается получить значения

Буду рада, если кто-то подскажет как это исправить

$('.button').click(function() {

  var table_A = $('#Atable'),
    row_A = $('tr', table_A),
    coll_A = $('#Atable td input').val(),
    marix_A = [];

  row_A.each(function() {
    marix_A.push($(coll_A, this));
  });
  alert(marix_A);

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="input_matrixA" id="Atable">
  <tr>
    <td>
      <input class="elem_matrix" placeholder="a1.1" type="text">
    </td>
    <td>
      <input class="elem_matrix" placeholder="a2.1" type="text">
    </td>
  </tr>
  <tr>
    <td>
      <input class="elem_matrix" placeholder="a2.1" type="text">
    </td>
    <td>
      <input class="elem_matrix" placeholder="a2.2" type="text">
    </td>
  </tr>
</table>
<button type="button" class="button">Кнопка</button>

1

1 ответ 1

1

Вопрос был решен

$('.button').click(function () {    
    var matrix = [];
    $('#Atable tr').each(function() {
        var values = [];
        $(this).find("input").each(function(){
            values.push($(this).val());
        });
        matrix.push(values);
    });
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.