使用jQuery获取表中特定行的值 [英] get value of a specific row of a table using jquery

查看:69
本文介绍了使用jQuery获取表中特定行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery获取表的特定行值(例如第五列的第三行). 我试过了:

How can I get a specific row value of a table(for exampe third row of fifth column) using jquery. I tried:

var t = document.getElementById('table');

    var val1 =$(t.rows[2].cells[4]).val();
    alert(val1);

但是它什么也没显示

推荐答案

尝试使用 :eq() 在这种情况下的选择器

Try using :eq() selector at this context

.val()仅适用于输入元素,您应该使用.text()来检索其文本内容,

.val() is only applicable for input elements, you should use .text() instead to retrieve its text content,

var val1 =$(t).find('tr:eq(2) td:eq(4)').text();
alert(val1);

或者,

alert($('#table tr:eq(2) td:eq(4)').text());

这篇关于使用jQuery获取表中特定行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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