简体   繁体   English

获取包含tds的第一个tr

[英]get the first tr that contains tds

In jquery how do I get the first table row that contains <td>s 在jQuery中,如何获取包含<td>s的第一行

So far my code looks like this but its not working? 到目前为止,我的代码看起来像这样,但是不起作用?

$('#mytable tr').has('td:first').html();

thanks 谢谢

您可以找到第一个TD的父母。

$("#mytable td:first").parent().html();

You could try 你可以试试

$($("#mytable").find('tr')[0]).find('td')

In this case you can iterate through rows and fetch the tds 在这种情况下,您可以遍历行并获取tds

$($($("#mytable").find('tr')[0]).find('td')[0]).text()
$($($("#mytable").find('tr')[0]).find('td')[1]).text()

尝试使用此:

$("#mytable td:first ").parents('tr').html();

Try this, jQuery maintains the element indices while selecting them - 试试这个,jQuery在选择元素索引时会维护它们-

$('#mytable td').eq(0).parent();

So in effect, this will select the first td in your table and return the parent, which should be a tr element, by convention 因此,实际上,这将选择表中的第一个td并按照约定返回父级,该父级应为tr元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM