开发者

JQuery: Get last td in tr within .each loop

开发者 https://www.devze.com 2022-12-17 21:06 出处:网络
I\'m trying to loop through a table to create a csv string. I do some sorting through jquery on the table so I want to be able to get the resulting sorted data. Problem is I want to identify each new

I'm trying to loop through a table to create a csv string. I do some sorting through jquery on the table so I want to be able to get the resulting sorted data. Problem is I want to identify each new row, so add a \n or something after the last td of every row. The code below just isnt right. Any pointers appreciated.

function GetCsv()开发者_如何学运维 {
        var strCSV = '';
        $('#MyTable tr').each(function() {
            var lis = $(this).siblings;
            for (var i = 0; i < lis.length; i++) {
                strCSV += $(this).find("td").eq(i).html();
            }
            strCSV += 'New line';
        });
    }


try:

function GetCsv() {
        var strCSV = '';
        $('#MyTable tr').each(function() {
            $(this).children().each(function(){
                strCSV += $(this).html();
            })
            strCSV += 'New line';
        });
    }
0

精彩评论

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

关注公众号