jQuery-选择给定行的第一个单元格? [英] jQuery - Select first cell of a given row?

查看:186
本文介绍了jQuery-选择给定行的第一个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,其中一列包含图片.当我单击图像时,想要获取该行第一列的文本值.

I have a table with images in one column. When I click the image, would like to get the text value of the first column in that row.

我可以得到整行:

var a = $(this).parents('tr').text();

但是,我无法隔离该行的第一个单元格.

However, I cannot isolate the first cell of the row.

我尝试过

var a = $(this).parents('tr td:first').text();

但这只是返回整个表的第一个单元格.

But that just returns the first cell of the entire table.

有人可以帮我吗?

谢谢.

推荐答案

怎么样?

var a = $('td:first', $(this).parents('tr')).text();

这篇关于jQuery-选择给定行的第一个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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