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';
});
}
精彩评论