开发者

Trying to add each table item to an array using JQuery

开发者 https://www.devze.com 2023-03-25 12:09 出处:网络
Basically what the title says... just having trouble getting it to work and couldn\'t find a solution online.

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());
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消