테이블에서 데이터를 가져와 배열에 저장해야합니다. 테이블의 각 행은 배열 내의 새로운 배열이어야합니다. 기본적으로 HTML은 다음과 같습니다 요법배열 배열 내에서 테이블 데이터 저장소 찾기
<table id="contactlisttable">
<tr>
<th>Name</th>
<th>Title</th>
<th>Phone</th>
</tr>
<tr>
<td class="contactlist contactlistlastfirst">Joey</td>
<td class="contactlist contactlisttitle">webdesigner</td>
<td class="contactlist contactlistphone">5555555</td>
</tr>
<tr>
<td class="contactlist contactlistlastfirst">Anthony</td>
<td class="contactlist contactlisttitle">webdesigner</td>
<td class="contactlist contactlistphone">5555555</td>
</tr>
</table>
... 여기
내 코드jQuery(document).ready(function(){
$(function(){
var $table = $("#contactlisttable"),
$headerCells = $table.find("tr th"),
$myrows = $table.find("tr"); // Changed this to loop through rows
var headers = [],
rows = [];
$headerCells.each(function() {
headers[headers.length] = $(this).text();
});
$myrows.each(function() {
$mycells = $myrows.find("td.contactlist"); // loop through cells of each row
cells = []
$mycells.each(function() {
cells.push($(this).text());
});
if (cells.length > 0) {
rows.push(cells);
}
});
console.log(headers);
console.log(rows);
});
});
내 현재 코드 끈다
[["Waddell, Joey", "webdesigner", "", 15 more...], ["Waddell, Joey", "webdesigner", "", 15 more...],
원하는 출력이 될 것입니다 :
["Name","Title","Phone"]
[["Joey","webdesigner","555555"]
["Anthony","webdesigner","555555"]]
여기에 큰 내 코드 http://jsfiddle.net/joeylobo/m4dW6/ – user2882684