jQuery获取表中单击的tr的第二到第十td的值。我已经有了第一个

问题描述:

                    $("#existcustomers tr").click(function () {
                        var td1 = $(this).children("td").first().text();
                        alert(td1);
                    });

我也需要td2-td10的值。我似乎无法弄清楚如何实现这一目标。我尝试以相同的方式使用 .second(),但这似乎打破了编程。有谁知道如何实现以下td?

I need the value of td2-td10 as well. I can't seem to figure out how to accomplish this. I tried using .second() in the same fashion but that seems to be breaking the programming. Does anyone know how this would be accomplished for the following td's?

要按索引获取特定单元格,您可以使用:

To get a specific cell by index, you can use :

$(this).children(":eq(1)")

要获得前10个孩子,请使用:

To get the first 10 children, use :

$(this).children(":lt(10)")

如果你想得到在数组的单独单元格中的内容,你可以做

If you want to get the content in separate cells of an array, you can do

var texts = $(this).children(":lt(10)").map(function(){return $(this).text()});

这样会产生如下数组:

["contentofcell1", "cell2", "3", "cell 4", "five", "six", "sieben", "otto", "neuf", "X"]