[英]get value of a specific row of a table using jquery
How can I get a specific row value of a table(for exampe third row of fifth column) using jquery. 如何使用jquery获取表的特定行值(例如第五列的第三行)。 I tried: 我试过了:
var t = document.getElementById('table');
var val1 =$(t.rows[2].cells[4]).val();
alert(val1);
But it is showing nothing 但它什么也没有显示出来
Try using :eq()
selector at this context 尝试在此上下文中使用:eq()
选择器
.val()
is only applicable for input elements, you should use .text()
instead to retrieve its text content, .val()
仅适用于输入元素,您应该使用.text()
来检索其文本内容,
var val1 =$(t).find('tr:eq(2) td:eq(4)').text();
alert(val1);
Or do, 或者,做
alert($('#table tr:eq(2) td:eq(4)').text());
.val
is for textBox, textAreas, use .text
instead like bellow. .val
用于.val
,textAreas,使用.text
而不是像bellow。
That should be something like bellow 那应该是像波纹管那样的东西
alert($('table tr').eq(2).find('td').eq(4).text())
I've added the selectors according to my DEMO, please change it accordingily, because I don't have your HTML 我根据我的DEMO添加了选择器,请根据我的要求进行更改,因为我没有您的HTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.