jQuery获取表中单击的tr的第二到第十td的值。我已经有了第一个 [英] jQuery getting the value of the second through tenth td of the clicked tr in a table. I already have the first

查看:133
本文介绍了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"]

这篇关于jQuery获取表中单击的tr的第二到第十td的值。我已经有了第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆