Trying to add each table item to an array using JQuery
Basically what the title says... just having trouble getting it to work and couldn't find a solution online.
Code:
var arr=new Array();
$('#tableC tr')开发者_运维问答.each(function() {
var tr = $(this);
tr.find('td').each(arr, function() {
$(this).val();
});
});
Try this
var arr = [];
$('#tableC td').each(function() {
arr.push($(this).text());
});
You're completely miscalling each
.
Instead, write
tr.find('td').each(function() {
arr.push($(this).val());
});
You could also write
var arr = $("#tableC tr td").map(function() { return $(this).val(); }).get();
Something along these lines?
http://jsfiddle.net/pPxcE/
Edit
code
var arr=new Array();
$('#tableC tr').each(function() {
var tr = $(this);
tr.find('td').each(function() {
arr.push($(this).text());
});
});
精彩评论