在当前 $(this) 选择器中选择内容 jquery

Selecting content within the current $(this) selector jquery

您可以查看我的 jsfiddle 以了解我正在尝试做的事情的示例。这是有问题的 Javascript 代码:

$("#div_games table tr").each(function(index) {
    var num = index;
    console.log($(this).text());
});

而 table 来自 Hockey-reference.com

我想将每一行 (tr) 组织成基于 csv 的模式。这是输出的一个小例子:

Date,Visitor,G,Home,G
1917-12-19,Toronto Arenas,9,Montreal Wanderers,10

这是前两行输出的样子。

我的问题仅仅是关于如何在每个 tr 和其中的每个 td 之间迭代?

我想做这样的事情:

$("#div_games table tr").each(function(index) {
    $(this ".td").each(function(index) {
        console.log($(this).text + ',');
    });
});

我知道这段代码行不通,但有没有办法做到这一点?作为旁注,我使用的是基于 node.js 的 Cheerio,而不是 jquery.

试试这个

$(this).find('td').each(function(index) {
   console.log($(this).text() + ',');
});

$('td', this).each(function(){}); 应该可以解决问题。