0

すべてのテーブル値を取得し、それらをコントローラーに送信して処理する必要があります!

ここに私のテーブルがあります:

<table id="test">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>4</td>
    <td>6</td>
    <td>7</td>
  </tr>
</table>

この 6 つの値を配列に取得し、処理のために ajax でスクリプトに送信するにはどうすればよいですか?

編集:フォームがデータを使用してajaxで送信されたときのようなもの:

serialize("#form")
4

1 に答える 1

2
var values = $('#test td')  // Find all <td> elements inside of an element with id "test".
    .map(function(i, e){    // Transform all found elements to a list of jQuery objects...
        return e.innerText; // ... using the element's innerText property as the value.
    })
    .get();                 // In the end, unwrap the list of jQuery objects into a simple array.

ここで働くフィドル。


ES6 では、これがもう少しエレガントに見えます。

let values = $('#test td')
    .map((index, element) => element.innerText)
    .get();
于 2013-10-25T12:45:21.577 に答える