如何使用jQuery在html页面中选择第一个表的第一行? [英] How to select first row of the first table in an html page using jQuery?

查看:127
本文介绍了如何使用jQuery在html页面中选择第一个表的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的HTML页面中有多个表(没有id属性),那么如何使用jQuery选择器选择第一个表的第一行或任何特定的表?

解决方案

  $(table:first> tr:first)
/ pre>

  $(table:first) .find(tr:first)


$ b b

  $(table:first)。children(tr:first)

  $(table)。eq(0).children ).eq(0)

所以如果我理解后续问题...

  $(table:eq(1)tr:has(table:eq(2)))

转换为:如果tr具有第三个表,则获取第二个表中的任何tr



  $(table)。eq(1).children(tr:has (2)))


Suppose if I have multiple tables in my HTML page (without their 'id' attribute), so how can I select first row of the first table or any specific table using jQuery selectors?

解决方案

$("table:first > tr:first")

or

$("table:first").find("tr:first")

or

$("table:first").children("tr:first")

or

$("table").eq(0).children("tr").eq(0)

So if I understand the followup question...

$("table:eq(1) tr:has(table:eq(2))")

translates to: get any tr's in the 2nd table's if the tr has a 3rd table

or

$("table").eq(1).children("tr:has(table:eq(2))")

这篇关于如何使用jQuery在html页面中选择第一个表的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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